I am trying to extend the SignalR Hub class to create a base class that is a SignalR Hub at it’s core but with some extra pzazz.
My base class:
public class MyBaseHub : Hub
{
protected ISession NhSession { get; set; }
public MyBaseHub(ISession nhSession)
{
NhSession = nhSession;
}
}
My derived class:
public class MyDerivedHub : MyBaseHub
{
public MyDerivedHub(ISession nhSession) : base(nhSession) { }
}
The above builds fine, but the SignalR generated javascript throws an error and I cannot create a connection on the client. There was more code in my base class, but I took it all out to try and narrow down the issue and found the problem is on the client side.
The generated Javascript throws an exception, “Uncaught SyntaxError: Unexpected Number”, when defining the MyBaseHub hub client:
myBaseHub`1: { generated properties go in here }
So I’m guessing that SignalR hubs can only be inherited once? Does anyone know if what I’m trying to do is possible?
Your question says the base hub is generic but the code sample doesn’t show it. If you make the class abstract, the proxy generator won’t pick it up. Also, you can rename hubs by using the
[HubName]attribute.