Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active December 25, 2015 22:19
Show Gist options
  • Save isaacabraham/7048950 to your computer and use it in GitHub Desktop.
Save isaacabraham/7048950 to your computer and use it in GitHub Desktop.
SignalR with IoC
/// <summary>
/// Uses Unity to create Hubs - and ONLY Hubs.
/// </summary>
// Register with GlobalHost.DependencyResolver.Register(typeof(IHubActivator), () => unityHubActivator);
public class UnityHubActivator : IHubActivator
{
private readonly IUnityContainer container;
public UnityHubActivator(IUnityContainer container)
{
this.container = container;
}
public IHub Create(HubDescriptor descriptor)
{
return (IHub)container.Resolve(descriptor.HubType);
}
}
public class ExampleHub : Hub
{
private readonly IMyService myService;
private readonly ILogger logger;
public ExampleHub(IMyService myService, ILogger logger)
{
this.myService = myService;
this.logger = logger;
}
// Blah blah....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment