forked from SignalR/SignalR
-
Notifications
You must be signed in to change notification settings - Fork 0
Extensibility
davidfowl edited this page May 9, 2012
·
27 revisions
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.
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());The following lists the pluggable interfaces in SignalR.
-
IMessageBus- Message bus. -
IConnectionIdGenerator- Generates connection ids. -
IAssemblyResolver- Locates assemblies to find hubs in. -
IJavaScriptProxyGenerator- Generates the client proxy for hubs.
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: