Skip to content
wtilton edited this page May 10, 2012 · 27 revisions

Extensiblity

SignalR is built with dependency injection in mind. You can replace most of SignalR pieces with your own implementations and even replace the IDependencyResolver with one of your own. If you're familiar with DI in ASP.NET MVC, then it should feel similar.

Replacing individual components

You can replace individual parts of SignalR without replacing the DependencyResolver by calling

GlobalHost.DependencyResolver.Register(type, Func<object>):
GlobalHost.DependencyResolver.Register(typeof(IConnectionIdFactory), () => new CustomIdFactory());

Replaceable components

The following lists the pluggable interfaces in SignalR.

  • IMessageBus - Message bus.
  • IConnectionIdGenerator - Generates connection ids.
  • IAssemblyLocator - Locates assemblies to find hubs in.
  • IJavaScriptProxyGenerator - Generates the client proxy for hubs.

Replacing the DependencyResolver

You can change the DependencyResolver to use your DI container of choice by setting GlobalHost.DependencyResolver.

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        GlobalHost.DependencyResolver = new CustomResolver();
 
        RouteTable.Routes.MapHubs();
    }
}

Optionally, if you don't want to use the global resolver you can set the resolver for specific connections when routes:

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.MapHubs(new CustomResolver());
    }
}

There are already some implementations in the community:

Clone this wiki locally