1

SignalR has a Hub class that looks like this:

  public abstract class Hub<T> : Hub where T : class
  {
    protected Hub();
    public IHubCallerClients<T> Clients { get; set; }
  }

public interface IHubCallerClients : IHubCallerClients<IClientProxy>, IHubClients<IClientProxy>

Which uses a IClientProxy type so you can call interface methods instead of SendAsync() on Clients. I want to do the same thing with the Serverless Hub class which does not have a generic constructor so how could I accomplish this? I've tried just inheriting and hiding the base property like so:

public abstract class ServerlessHub<T> : ServerlessHub
      where T : class
  {
    protected ServerlessHub(IServiceHubContext hubContext = null, IServiceManager serviceManager = null)
      : base(hubContext, serviceManager)
    {
    }

    public new IHubClients<T> Clients { get; }
  }

but I get a null reference exception for Clients.

Bugbeeb
  • 2,021
  • 1
  • 9
  • 26

1 Answers1

1

I believe this isn't possible yet, see this issue on Github: Support strongly typed Hub Clients

Stanislas
  • 1,893
  • 1
  • 11
  • 26
  • 1
    Thanks for sharing, it got me to snooping in signalR repos and I ended up making my own! I shared the code in that same issue – Bugbeeb Feb 27 '21 at 14:55