Register event proxy - AndersMalmgren/SignalR.EventAggregatorProxy GitHub Wiki

Dot Net Core Pipeline

The event aggregator is setup in two steps in Startup.cs, first,

public void ConfigureServices(IServiceCollection services)
{
    ...
    services
        .AddSignalREventAggregator()
        .AddSignalR()

        ...
}

This will bind all dependencies. To register the hub and event proxy call

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ 
    ...
    app
      .UseEventProxy()
      .UseSignalREventAggregator();
    ...
}

IMPORTANT You no longer tell the library which types are events by passing a generic argument with the base event. Instead you implement IEventTypeFinder and register it with the DI. It should supply the library with a list of concrete types. They do not need to share same base class.

services
    .AddSignalREventAggregator()
    .AddSingleton<IEventTypeFinder, EventTypeFinder>()

Register script proxy

UseEventProxy will inject a dynamic script with all event types declared, register this script like

<script src="/eventAggregation/events" asp-append-version="true"></script>

Dotnet CLI

You can also benefit from buildtime generation of the event proxy by using the CLI method described here.

SignalR 2.x SystemWeb Pipeline

In your SignalR 2.0 Configure method add

public static void Configuration(IAppBuilder app)
{
    app.MapSignalR();
    app.MapEventProxy<EventBase>();
}

NOTE SystemWeb hosted projects needs SignalR.EventAggregatorProxy.SystemWeb from version 1.5.155

SignalR 2.x self hosted Pipeline

The library does not require a web server to run, you can host it from a Service or Console project. Calling app.MapEventProxy<EventBase>(); is then redundant (And not part of Core from version 1.5.55) since part of its job is to register the event proxy script used by the JavaScript client. You need to call Bootstrapper.Init<EventBase>(); instead that is normally called by MapEventProxy.

public static void Configuration(IAppBuilder app)
{
    app.MapSignalR();
    Bootstrapper.Init<EventBase>();
}

SignalR 1.x Pipeline (Deprecated)

You need to download version 1.1.85-SignalR-1x for 1.x support. From your applications Start method do

    public class Global : System.Web.HttpApplication
    {
        public void Application_Start()
        {
            // Register the default hubs route: ~/signalr
            RouteTable.Routes.MapHubs();
            RouteTable.Routes.MapEventProxy<EventBase>();
        }
    }

The generic argument is the base class for all events that you want to forward to clients. Do not forget to MapHubs (1.x) / MapSignalR (2.x). The proxy uses its own Hub, EventAggregatorProxyHub. If you have overridden the default assembly locator make sure that MapHubs can find the above Hub.

Register script proxy

MapEventProxy will inject a dynamic script with all event types declared, register this script like

@Scripts.Render("~/eventAggregation/events")
⚠️ **GitHub.com Fallback** ⚠️