title: SignalR resolving a hub context from a change event handler
body: <p>I have an issue where I can't seem to send new data to the connected Signal R clients from a <code>ChangedEventHandler</code>. The docs says that I can get the hub context by using:-</p>
  
  <pre><code>var context = GlobalHost.ConnectionManager.GetHubContext&lt;ChatHub&gt;();
  context.Clients.All.addToList(insertedCustomer);
  </code></pre>
  
  <p>However nothing gets sent to the clients (checked on fiddler) or any errors reported. My onchange event is wired up at the moment from <code>Application_Start</code> as I am creating a proof of concept.  I should point out the hub does work on start up and retrieves the data from the initial <code>GetAll</code> call</p>
  
  <pre><code>    protected void Application_Start()
      {
          ...
          _sqlTableDependency.OnChanged += _sqlTableDependency_OnChanged;
          _sqlTableDependency.Start();
          ...
      }
  
      private void _sqlTableDependency_OnChanged(object sender, RecordChangedEventArgs&lt;BiddingText&gt; e)
      {
          switch (e.ChangeType)
          {
              case ChangeType.Insert:
                  foreach (var insertedCustomer in e.ChangedEntities)
                  {
                      var context = GlobalHost.ConnectionManager.GetHubContext&lt;ChatHub&gt;();
                      context.Clients.All.addToList(insertedCustomer);
  
                      biddingTextList.Add(insertedCustomer);
                  }
                  break;
          }
      }
  </code></pre>
  
  <p>When I put a breakpoint on the hub <code>context</code> I get my ChatHub back. </p>
  
  <p>My Javascript code:</p>
  
  <pre><code>$.connection.hub.url = "http://localhost:37185/signalr";
  
  // Reference the auto-generated proxy for the hub.
  var chat = $.connection.chatHub;
  
  chat.client.initialText = function(data) {
      var index;
      //console.log(data.length);
      for (index = 0; index &lt; data.List.length; ++index) {
          $('#list').append("&lt;li&gt;" + data.List[index].text + "&lt;/li&gt;");
      }
  };
  
  chat.client.addToList = function(data) {
      console.log(data);
      $('#list').append("&lt;li&gt;" + data.text + "&lt;/li&gt;");
  };
  
  // Start the connection.
  $.connection.hub.start({ jsonp: true }).done(function () {
      chat.server.getAll(1831);
  });
  </code></pre>
  
  <p>My Hub code:</p>
  
  <pre><code>public class ChatHub : Microsoft.AspNet.SignalR.Hub
  {
      private readonly IMediator mediator;
  
      public ChatHub(IMediator mediator)
      {
          this.mediator = mediator;
      }
  
      public void GetAll(int saleId)
      {
          var model = mediator.Request(new BiddingTextQuery { SaleId = saleId});
          Clients.Caller.initialText(model);
      }
  
  }
  </code></pre>
  
  <p>Not sure if this is relevant but the <code>Clients.Connection.Identity</code> is different everytime I use <code>GlobalHost.ConnectionManager.GetHubContext&lt;ChatHub&gt;();</code></p>
  
  <p>Can anyone help?</p>