Skip to content

Consider allowing hinheriting HubMethodNameAttribute in SignalR hub classes #64291

@paulomorgado

Description

@paulomorgado

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

When using a strongly typed SignalR hub, HubMethodNameAttribute in the client type is used, but the same doesn't happen if the server methods are declared in an implemented interface.

Given:

public interface INotifications
{
    public const string ReceiveMessageMethodName = "ReceiveMessage";

    [HubMethodName(ReceiveMessageMethodName)]
    public Task ReceiveMessageAsync(string user, string message);
}
public interface IMethods
{
    public const string SendMessageMethodName = "SendMessage";

    [HubMethodName(SendMessageMethodName)]
    public Task SendMessageAsync(string user, string message);
}

In this hub:

public class NotificationsHub : Hub<INotifications>, IMethods
{
    public async Task SendMessageAsync(string user, string message)
    {
        await Clients.All.ReceiveMessageAsync(user, message);
    }
}

The client method is ReceiveMessage and the server method is SendMessageAsync.

Describe the solution you'd like

The server method should be SendMessage.

Additional context

By changing this code to:

            var methodName =
                methodInfo.GetCustomAttribute<HubMethodNameAttribute>(inherit: true)?.Name ??
                methodInfo.Name;

it should work.

This is a breaking change, though,

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions