Skip to content
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

Add SignalR Core integration package #27

Open
dotnetjunkie opened this issue Dec 4, 2019 · 4 comments
Open

Add SignalR Core integration package #27

dotnetjunkie opened this issue Dec 4, 2019 · 4 comments
Labels

Comments

@dotnetjunkie
Copy link
Collaborator

dotnetjunkie commented Dec 4, 2019

This package should do the following:

  • Implement a SimpleInjectorHubActivator<T> class
  • Add an extension method for registration of this class
  • Add an extension method that allows auto-registration of Hub classes, similar to the RegisterMvcControllers 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 the Hub implementation does not override Dispose(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 implemented IDisposable (and it shouln't have).

There are other complications, such as discussed here that should be taken into consideration, which are:

  • Hub classes do not always run in a web request (for instance with LongPolling), which means that they can be resolved without an active Simple Injector Scope.
  • This means SimpleInjectorHubActivator<T> must create a new Scope within its Create method, and dispose of the Scope in the Release method.
  • Although the creation of, and disposing of a scope, could be skipped in case an active scope (i.e. a web request scope) already exists, that could lead to complications, because the request might already have ended in some cases.
  • 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 active IServiceScope/IServiceProvider instance to prevent Simple Injector from creating a new IServiceScope internal, which would, again, lead to multiple instances of scoped registrations, but now for ASP.NET Core registered types. The 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.

The following issues should be taken into consideration:

@dotnetjunkie
Copy link
Collaborator Author

For now, we made the decision not to add an integration package. This page describes how to integrate Simple Injector with SignalR Core.

@Sprint-Debugger
Copy link

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

@dotnetjunkie
Copy link
Collaborator Author

@Sprint-Debugger, please create a new issue with a minimal, reproducible example that demonstrates your issue.

@lneshev
Copy link

lneshev commented Oct 2, 2020

@Sprint-Debugger, please create a new issue with a minimal, reproducible example that demonstrates your issue.

It is here: simpleinjector/SimpleInjector#851

Repository owner locked and limited conversation to collaborators Dec 16, 2020
Repository owner unlocked this conversation Feb 17, 2022
@dotnetjunkie dotnetjunkie transferred this issue from simpleinjector/SimpleInjector Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants