title: Using Unity IoC to register and resolve SignalR hubs
body: <p>I think I'm missing something very simple and maybe just need a new set of eyes.  I have an ASP.NET MVC application.  In that app, I am using Unity for my IoC to handle dependency injection.  Each of my repositories need to have a database factory injected into it and each database factory needs to have a principal injected into it.  So far, I've been utilizing the PerRequestLifetimeManager to register these.  </p>
  
  <pre><code>//Repositories
  
  container.RegisterType&lt;ChatMessageRepository&gt;(new PerRequestLifetimeManager());
             container.RegisterType&lt;SignalRConnectionRepository&gt;(new PerRequestLifetimeManager());
  
  //Context
  container.RegisterType&lt;IPrincipal, Principal&gt;(new PerRequestLifetimeManager());
  container.RegisterType&lt;IDatabaseFactory, DatabaseFactory&gt;(new PerRequestLifetimeManager());
  container.RegisterType&lt;UnitOfWork&gt;(new PerRequestLifetimeManager());
  </code></pre>
  
  <p>Logically, I've tried to register my Hub in the same fashion.</p>
  
  <pre><code>container.RegisterType&lt;ChatHub&gt;(new PerRequestLifetimeManager()); 
  </code></pre>
  
  <p>However, whenever I run my app and navigate away from my chat page, I get a "Resolution of the dependency failed" exception and the InnerException tells me "Operation is not valid due to the current state of the object."  I've also tried using the default (Transient), PerResolve, and ContainerControlled lifetime Unity managers when registering these guys and cannot seem to get resolve my issue. </p>
  
  <p>Could someone just provide me some demo code with how you used Unity in an ASP.NET MVC application to handle dependency injection into your signalr hubs?</p>
  
  <p>Here's where Unity will inject parameters into my SignalR Hub</p>
  
  <pre><code>public class ChatHub : Hub
  {
      private readonly ChatMessageRepository _chatMessageRepository;
      private readonly SignalRConnectionRepository _signalRConnectionRepository;
      private readonly UnitOfWork _unitOfWork;
  
      public ChatHub(ChatMessageRepository chatMessageRepository,
          SignalRConnectionRepository signalRConnectionRepository,
          UnitOfWork unitOfWork)
      {
          _chatMessageRepository = chatMessageRepository;
          _signalRConnectionRepository = signalRConnectionRepository;
          _unitOfWork = unitOfWork;
      } ... }
  </code></pre>
  
  <p>Thanks!</p>