✅ Attribute based definition vs. Interface based definition
Greetings,
I'm working on my Source Generator that generates boilerplate code for SignalR communication.
For this I have basically two ways of defining the interface the generator uses to generate the actual code.
I've tried my best to describe it in this issue: https://github.com/MichaelHochriegl/SignalRGen/issues/74
But here is the quick comparison:
{
// This will have the client-to-server methods
Task<string> SentByTheClient(string message);
}
[HubClient(HubUri = "interface-based-hub")]
public interface IInterfaceBasedHub : IBidirectionalHub<IInterfaceBasedHubServerMethods, IInterfaceBasedHubClientMethods>
{
}
```
Which do you prefer and why?
Thanks for your feedback
I'm working on my Source Generator that generates boilerplate code for SignalR communication.
For this I have basically two ways of defining the interface the generator uses to generate the actual code.
I've tried my best to describe it in this issue: https://github.com/MichaelHochriegl/SignalRGen/issues/74
But here is the quick comparison:
- Attribute based```csharp[HubClient(HubUri = "example")]public interface IExampleHubClient : IBaseFromOtherAssembly{ Task ReceiveExampleCountUpdate(int count); [ClientToServerMethod] Task<string> SendExampleMessage(string myClientMessage); [ClientToServerMethod] Task SendWithoutReturnType(string myClientMessage);}```
- Interface based```csharppublic interface IInterfaceBasedHubServerMethods{ // This will have the server-to-client methods Task SentByTheServer(string message);}
{
// This will have the client-to-server methods
Task<string> SentByTheClient(string message);
}
[HubClient(HubUri = "interface-based-hub")]
public interface IInterfaceBasedHub : IBidirectionalHub<IInterfaceBasedHubServerMethods, IInterfaceBasedHubClientMethods>
{
}
```
Which do you prefer and why?
Thanks for your feedback
GitHub
Description Currently the source generator runs on HubClients defined via attributes (e.g. the ClientToServerMethod and ServerToClientMethod). Attribute-based example: [HubClient(HubUri = "exa...