SignalR SourceGenerator attribute API
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
## Background and Motivation
For PR https://github.com/dotnet/aspnetcore/pull/38025
We are adding a source generator for SignalR .NET clients to allow sharing strongly-typed interfaces between client and server. We have had the server side since first release and are now adding support for the client-side.
## Proposed API
```diff
namespace Microsoft.AspNetCore.SignalR.Client
{
+ [AttributeUsage(AttributeTargets.Method)]
+ public sealed class ClientHubAttribute : Attribute
+ {
+ }
+ [AttributeUsage(AttributeTargets.Method)]
+ public sealed class ServerHubProxyAttribute : Attribute
+ {
+ }
}
```
Package Name:
Microsoft.AspNetCore.SignalR.Client.SourceGenerator
Attribute DLL Name:
Microsoft.AspNetCore.SignalR.Client.SourceGenerator.HubProxyAttributes.dll
## Usage Examples
```csharp
internal static partial class ProxyExtensions
{
[ServerHubProxy]
public static partial T ServerHub(this HubConnection conn);
[ClientHub]
public static partial IDisposable CallbackRegistration(this HubConnection conn, T impl);
}
public interface IMyHub
{
Task GetNothing();
}
public interface IMyHubClient
{
Task ReceiveMessage(string message);
}
public class MyHubClient : IMyHubClient
{
public Task ReceiveMessage(string message)
{
Console.WriteLine(message);
return Task.CompletedTask;
}
}
var myHub = conn.ServerHub();
var dispose = connection.CallbackRegistration(new MyHubClient());
await myHub.GetNothing();
```
## Alternative Designs
HubServerProxyAttribute
HubClientProxyAttribute
ClientMethodsAttribute
SignalRClientAttribute
ClientRegistrationAttribute
Contributor guide
Assessment
This issue has not been assessed yet.