Open
Description
Background and Motivation
For PR #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
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
internal static partial class ProxyExtensions
{
[ServerHubProxy]
public static partial T ServerHub<T>(this HubConnection conn);
[ClientHub]
public static partial IDisposable CallbackRegistration<T>(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<IMyHub>();
var dispose = connection.CallbackRegistration<IMyHubClient>(new MyHubClient());
await myHub.GetNothing();
Alternative Designs
HubServerProxyAttribute
HubClientProxyAttribute
ClientMethodsAttribute
SignalRClientAttribute
ClientRegistrationAttribute