Which is the advantage to use grpc code first? Thinking in DDD

Viewed 27

According to documentation of Microsoft, it is possible to use classes instead of protobuf to transfer the data, this is the documentation. https://docs.microsoft.com/en-us/aspnet/core/grpc/code-first?view=aspnetcore-6.0

I am try to do some tries with gRPC and DDD.

In the server side, I have the server gRPC, that uses a repository to get data. The repository returns domain classes.

But to can send classes with gRPC code first, I need to decorate the classes with [DataContract] and the properties of the classes with [DataMember(Order = 1)].

Well, how the classes of the domain shouldn't be decorated, then the only way that I guess it is possible to send to the client the information is creating intermediate classes, gRPC classes, to convert domain classes to classes that can be serialized and send to the client.

So here is my question, if this is the unique solution, I have to convert domain classes to classes that can be serialized, then, which is the advantage to create this gRPC classes instead of use directly probuf? I could convert domain classes to protobuf and I would have the same work, convert domain classes to something that can be serializable and send to the client. So I don't see the advantage of the gRPC code first.

Thanks.

0 Answers
Related