Skip to content

Instantly share code, notes, and snippets.

@ChristianWeyer
Created October 1, 2012 18:18
Show Gist options
  • Save ChristianWeyer/3813468 to your computer and use it in GitHub Desktop.
Save ChristianWeyer/3813468 to your computer and use it in GitHub Desktop.
Simple ASP.NET Web API & SignalR integration.
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; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment