title: SignalR : How to use IHubContext<THub,T> Interface in ASP.NET MVC?
body: <p>I have been trying to used the following approach in my ASP.NET MVC project where <code>Microsoft.AspNet.SignalR</code> library is used:</p>
  
  <pre><code>public interface ITypedHubClient
  {
    Task BroadcastMessage(string name, string message);
  }
  </code></pre>
  
  <p>Inherit from Hub:</p>
  
  <pre><code>public class ChatHub : Hub&lt;ITypedHubClient&gt;
  {
    public void Send(string name, string message)
    {
      Clients.All.BroadcastMessage(name, message);
    }
  }
  </code></pre>
  
  <p>Inject your the typed hubcontext into your controller, and work with it:</p>
  
  <pre><code>public class DemoController : Controller
  {   
    IHubContext&lt;ChatHub, ITypedHubClient&gt; _chatHubContext;
  
    public DemoController(IHubContext&lt;ChatHub, ITypedHubClient&gt; chatHubContext)
    {
      _chatHubContext = chatHubContext;
    }
  
    public IEnumerable&lt;string&gt; Get()
    {
      _chatHubContext.Clients.All.BroadcastMessage("test", "test");
      return new string[] { "value1", "value2" };
    }
  }
  </code></pre>
  
  <p>However, there is no <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.signalr.ihubcontext-2?view=aspnetcore-2.2" rel="nofollow noreferrer"><code>IHubContext&lt;THub,T&gt;</code> Interface</a> in <code>Microsoft.AspNet.SignalR</code> library and I for this reason I cannot use <code>IHubContext</code> with two parameters (<code>IHubContext&lt;ChatHub, ITypedHubClient&gt; _chatHubContext;</code>). So, I am wondering if it is possible to a DI library or method. If so, how to fix this problem? </p>