-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SimpleInjector SignalR Core integration throws SimpleInjector.ActivationException on LongPolling #630
Comments
Can you post a full stack trace? |
Sure:
|
In your case, you need to implement a custom private sealed class SimpleInjectorScopeHubDispatcher<THub> : HubDispatcher<THub> where THub : Hub
{
private readonly Container container;
private readonly HubDispatcher<THub> decorated;
public SimpleInjectorScopeHubDispatcher(Container container, DefaultHubDispatcher<THub> decorated)
{
this.container = container;
this.decorated = decorated;
}
public override async Task DispatchMessageAsync(HubConnectionContext connection, HubMessage hubMessage)
{
using (this.BeginScope()) await this.decorated.DispatchMessageAsync(connection, hubMessage);
}
public override async Task OnConnectedAsync(HubConnectionContext connection)
{
using (this.BeginScope()) await this.decorated.OnConnectedAsync(connection);
}
public override async Task OnDisconnectedAsync(HubConnectionContext connection, Exception exception)
{
using (this.BeginScope()) await this.decorated.OnDisconnectedAsync(connection, exception);
}
public override IReadOnlyList<Type> GetParameterTypes(string name) => this.decorated.GetParameterTypes(name);
public override Type GetReturnType(string invocationId) => this.decorated.GetReturnType(invocationId);
private Scope BeginScope() => AsyncScopedLifestyle.BeginScope(this.container);
} Using this class, your Simple Injector/SignalR configuration will look as follows. services.AddSingleton(typeof(IHubActivator<>), typeof(SimpleInjectorHubActivator<>));
services.AddSingleton(typeof(DefaultHubDispatcher<>));
services.AddSingleton(typeof(HubDispatcher<>), typeof(SimpleInjectorScopeHubDispatcher<>)); |
Excellent, works great! Thanks for the quick reply. |
The introduction of Simple Injector v4.9 simplified the integration with SignalR Core. I updated the SignalR Core integration page accordingly. The described integration also fixes the long-polling problems. |
I have been using the integration sample suggested in #232 to integrate SimpleInjector with SignalR Core.
Everything works as expected until the protocol is set to LongPolling where the following exception is thrown:
I have put together a server and client example where it can be reproduced.
If you change the protocol at THIS line to LongPolling, you will see the exception thrown.
The SimpleInjector integration methods can found in
SimpleInjectorHelper
.The text was updated successfully, but these errors were encountered: