NetCoreServer
NetCoreServer copied to clipboard
Question: Correctly defining domain models for proto server/client
Is it possible to control the code gen output with attributes?
In the proto example the domain model contains something that resembles attributes in C# (words enclosed in square brackets), but I cannot find any documentation about their purpose or how they work. By their names however, it looks like the attributes are used to control some logic about what type of response or reject is expected for any given request.
The proto model sample I am referring to is here: https://github.com/chronoxor/NetCoreServer/blob/master/proto/simple.fbe
As a simple example, given the following domain model:
[request]
[response(HelloResponse)]
[reject(HelloReject)]
message HelloRequest
{
uuid [id] = uuid1;
string Message;
timestamp Sent;
}
message HelloResponse
{
uuid [id] = uuid1;
string ResponseMessaga;
}
message HelloReject
{
uuid [id] = uuid1;
string Error;
}
I would expect that the client/sender part of the code generation uses the [request], [response()] and [reject()] to generate only the handlers you would need, but I end up with a total of 9 generated handlers, namely:
ReceivedResponseHandler_HelloReject
ReceivedResponseHandler_HelloRequest
ReceivedResponseHandler_HelloResponse
ReceivedNotifyHandler_HelloReject
ReceivedNotifyHandler_HelloRequest
ReceivedNotifyHandler_HelloResponse
ReceivedRejectHandler_HelloReject
ReceivedRejectHandler_HelloRequest
ReceivedRejectHandler_HelloResponse
All these handlers makes it quite unclear which should be used when developing a client. As far as I can tell, for example the ReceivedResponseHandler_HelloReject
will never be used. Rather the ReceivedRejectHandler_HelloReject
is the one that would implemented in the consuming code.
Would it not make more sense if the only handlers being generated would be something like:
ReceivedRequestHandler_HelloRequest
ReceivedResponseHandler_HelloResponse
ReceivedRejectHandler_HelloReject
Comments and/or examples would be highly appreciated.
Is it possible to control the code gen output with attributes?
In short:
- If you generate the code: yes.
- If you use some special Microsoft attributes (for example: not-to-inline a method): then also yes.
The "Issues" section here is not used for questioning & answering how to code in .NET/C#. It exists for reporting issues (bugs) in NetCoreServer (or requests for features).
For more specific information about "Attributes" in .NET/C# please refer to:
@aqoamann Thanks for commenting, but I don't think you've read my question. Either that or I am very unclear. I am specifically asking about what seems like undocumented annotations in the FBE format. If you take a look at the domain model at https://github.com/chronoxor/NetCoreServer/blob/master/proto/simple.fbe you will see the attributes/annotations that I am referring to in my example.
My question relates to their functionality and usage, not .NET attributes in general.