title: Configuring Autofac for Dependency on SignalR Hub
body: <p>I would like to be able to inject a SignalR hub into other classes as a dependency so I can send messages to it from server code (independently of a direct AJAX call from a Javascript client).  Like this:</p>
  
  <pre><code>    private readonly IMyApplicationHub _signalHub;
  
      public HomeController(IMyApplicationHub signalHub)
      {
          _signalHub = signalHub;
      }
  </code></pre>
  
  <p>However, I don't how how to tell Autofac which instance of the hub to use - it doesn't seem to be the same instance that is created when a real client opens its connection.</p>
  
  <p>I'm finding that, if I want to refer to the "real" hub instance that SignalR is using, I have to maintain my own Singleton reference and set it the first time that a method (in this case, Init) is invoked from a real Javascript client.</p>
  
  <pre><code>public class MyApplicationHub : Hub, IMyApplicationHub
  {
      public static MyApplicationHub SingleInstance = null;
  
      public void Init(string message)
      {
          SingleInstance = this;
      }
  
      internal void SendMessage(string message, IEnumerable&lt;LinkDto&gt; links)
      {
          Clients.siteReceived(message);
      }
  }
  </code></pre>
  
  <p>I must be missing something.  Any assistance would be appreciated!  (Eventually, I'd also like to know how to constructor-inject dependencies into the SignalR hub itself, but that seems like a slightly different problem.)</p>