Open dotnetjunkie opened 4 years ago
For now, we made the decision not to add an integration package. This page describes how to integrate Simple Injector with SignalR Core.
For now, we made the decision not to add an integration package. This page describes how to integrate Simple Injector with SignalR Core.
Can you provide a full working example using this solution? I keep trying it whole day without a success! My problem is that the connection is established, but when I send a message from the server to the clients, the clients do not receive anything. If I remove just this line of code: ".AddControllerActivation();", it starts working, but then a controller might throw an exception if there is a dependency just in SimpleInjector container, but not in .NET Core's DI container. Versions I used (and tried): ASP.NET Core 3.1, SimpleInjector: from 4.9.1 to 5.0.0, @microsoft/signalr: 3.1.5
@Sprint-Debugger, please create a new issue with a minimal, reproducible example that demonstrates your issue.
@Sprint-Debugger, please create a new issue with a minimal, reproducible example that demonstrates your issue.
It is here: https://github.com/simpleinjector/SimpleInjector/issues/851
This package should do the following:
SimpleInjectorHubActivator<T>
classRegisterMvcControllers
of the ASP.NET Core MVC integration package. i.e. it should register Hub classes based on the selected lifestyle (ILifestyleSelectionBehavior
) and should suppress the disposable transient components warning in case theHub
implementation does not overrideDispose(bool)
.Especially this last point is the main reason why we need an integration package. Integrating SignalR without an integration package would have been trivial in case
Hub
would not have implementedIDisposable
(and it shouln't have).There are other complications, such as discussed here that should be taken into consideration, which are:
SimpleInjectorHubActivator<T>
must create a newScope
within itsCreate
method, and dispose of theScope
in theRelease
method.In case the absense of an active scope, the hub activator should be able to supply the Simple Injector ASP.NET Core integration with the activeThe hub should run in its own Simple Injector scope and MS.DI scope; reusing the same incoming MS.DI scope might have hard to predict side effects.IServiceScope
/IServiceProvider
instance to prevent Simple Injector from creating a newIServiceScope
internal, which would, again, lead to multiple instances of scoped registrations, but now for ASP.NET Core registered types.The following issues should be taken into consideration: