You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the following code to plug these integration points into the SignalR Core pipeline:
// Allows hubs to be registered as Scoped while having transient dependencies (not needed in >= v5.0).container.Options.UseLoosenedLifestyleMismatchBehavior=true;services.AddSignalR();services.AddSimpleInjector(container, options =>{});// Find all Hub implementations and register them as scoped.vartypes=container.GetTypesToRegister<Hub>(typeof(MyHub).Assembly);foreach(Typetypeintypes)container.Register(type,type,Lifestyle.Scoped);// NOTE: SimpleInjectorHubActivator<T> must be registered as Scopedservices.AddScoped(typeof(IHubActivator<>),typeof(SimpleInjectorHubActivator<>));
TIP: When sending SignalR messages from background threads compared to web requests, you try using IHubContext<THub> instead of the hub class itself, because the hub class, in that case, won't be fully initialized.
This next example shows this:
publicclassTestHandler:IHandleMessages<MessageSent>{privatereadonlyIHubContext<MyHub>_context;publicTestHandler(IHubContext<MyHub>context){_context=context;}publicasyncTaskHandle(MessageSentmessage){await_context.Clients.All.SendAsync("sendMessage","Message was sent!");}}
This post might be updated in case we find a better way of integrating with SignalR Core.
In case you have comments or found a bug, please open a new issue.
The text was updated successfully, but these errors were encountered:
Repository owner
locked and limited conversation to collaborators
Nov 4, 2018
To integrate with SignalR Core, you need add the following class to your project:
NOTE: This integration requires Simple Injector >= 4.9.
Use the following code to plug these integration points into the SignalR Core pipeline:
TIP: When sending SignalR messages from background threads compared to web requests, you try using
IHubContext<THub>
instead of the hub class itself, because the hub class, in that case, won't be fully initialized.This next example shows this:
This post might be updated in case we find a better way of integrating with SignalR Core.
In case you have comments or found a bug, please open a new issue.
The text was updated successfully, but these errors were encountered: