Skip to content

Instantly share code, notes, and snippets.

@ChristianWeyer
Created October 1, 2012 18:18

Revisions

  1. ChristianWeyer renamed this gist Oct 1, 2012. 1 changed file with 0 additions and 0 deletions.
  2. ChristianWeyer created this gist Oct 1, 2012.
    29 changes: 29 additions & 0 deletions webapi_signalr_integration
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    namespace WebApi.SignalR
    {
    /// <summary>
    /// Simple Web API & SignalR integration.
    /// No access to full hub, e.g. HubCallerContext.
    /// </summary>
    /// <typeparam name="THub"></typeparam>
    public abstract class HubApiController<THub> : ApiController
    where THub : IHub
    {
    private Lazy<IHubContext> hub = new Lazy<IHubContext>(
    () => GlobalHost.ConnectionManager.GetHubContext<THub>()
    );

    protected string ConnectionId
    {
    get
    {
    var connectionId = new FormDataCollection(Request.RequestUri).Get("connectionId");
    return connectionId;
    }
    }

    protected IHubContext Hub
    {
    get { return hub.Value; }
    }
    }
    }