-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Register Blazor's ComponentHub in the IServiceCollection #29194
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
Comments
@dotnetjunkie thanks for contacting us. I'm not very familiar with the problem. Maybe @davidfowl has some thoughts? Is there something you could do by adding a circuit handler and calling an API on your container to set the scope? |
Hi @javiercn, thank you for your comment.
I've done some testing with circuit handlers, but their execution doesn't seem to wrap a call to the hub activator. This makes them unsuited for applying ambient scoping, unless I'm missing something. |
Thanks for contacting us. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Hi. Thanks for contacting us. |
Some non-conforming DI Containers rely on the use of ambient state for providing scoping. This causes a challenge when it comes to integrating with with Blazor due to the way both Blazor and SignalR are set up.
Such container (such as Simple Injector) will have to replace SignalR's default
IHubActivator<T>
implementation in order to apply scoping. But even without ambient scoping, non-conformers will likely want to replace theIHubActivator<T>
in order to resolve application hubs. When replacingIHubActivator
, however, there is no way to callback into SignalR'sDefaultHubActivator<T>
to resolve framework hubs, such as Blazor'sComponentHub
, asDefaultHubActivator<T>
is internal.Implementing a custom
IHubActivator<T>
likely means choosing one of the following three options:DefaultHubActivator<T>
's behavior in order to resolve framework types likeComponentHub
ComponentHub
directly from the built-in containerComponentHub
directly from the third-party (non-conforming) containerAbout these options:
ComponentHub
is an internal type. Neither application code, nor a third-party can access this type and accessing using reflection is brittle as the internal type could change in the future.ComponentHub
is not registered in theIServiceCollection
.There are multiple possible solutions:
DefaultHubActivator<T>
public. This allows the custom activator to create or possibly inject the default activator and call itComponentHub
public. This allows an application developer or non-conforming integration package to register it in the application container, or optionally directly into theIServiceCollection
ComponentHub
into theIServiceCollection
. This allows a custom activator to resolve this type from the framework container without requiringComponentHub
to become public.I think adding
ComponentHub
to theIServiceCollection
is the easiest solution because it doesn't require making any type public, which saves writing and maintaining new documentation. AddingComponentHub
to theIServiceCollection
is likely a very low-risk operation. The risk of it breaking existing applications presumably is very low.The text was updated successfully, but these errors were encountered: