Skip to content

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

Closed
dotnetjunkie opened this issue Jan 10, 2021 · 5 comments
Closed

Register Blazor's ComponentHub in the IServiceCollection #29194

dotnetjunkie opened this issue Jan 10, 2021 · 5 comments
Labels
affected-very-few This issue impacts very few customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-server investigate severity-major This label is used by an internal tool

Comments

@dotnetjunkie
Copy link

dotnetjunkie commented Jan 10, 2021

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 the IHubActivator<T> in order to resolve application hubs. When replacing IHubActivator, however, there is no way to callback into SignalR's DefaultHubActivator<T> to resolve framework hubs, such as Blazor's ComponentHub, as DefaultHubActivator<T> is internal.

Implementing a custom IHubActivator<T> likely means choosing one of the following three options:

  1. Completely reimplement DefaultHubActivator<T>'s behavior in order to resolve framework types like ComponentHub
  2. Resolve ComponentHub directly from the built-in container
  3. Resolve ComponentHub directly from the third-party (non-conforming) container

About these options:

  • Option 1 is not desirable because of the amount of code duplication it causes for integration scenarios and the possibly conflicts when the default implementation changes in the future.
  • Option 3 is difficult to achieve because 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.
  • Option 2 is currently impossible because ComponentHub is not registered in the IServiceCollection.

There are multiple possible solutions:

  • Make SignalR's DefaultHubActivator<T> public. This allows the custom activator to create or possibly inject the default activator and call it
  • Make ComponentHub public. This allows an application developer or non-conforming integration package to register it in the application container, or optionally directly into the IServiceCollection
  • Register ComponentHub into the IServiceCollection. This allows a custom activator to resolve this type from the framework container without requiring ComponentHub to become public.

I think adding ComponentHub to the IServiceCollection is the easiest solution because it doesn't require making any type public, which saves writing and maintaining new documentation. Adding ComponentHub to the IServiceCollection is likely a very low-risk operation. The risk of it breaking existing applications presumably is very low.

@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Jan 10, 2021
@javiercn
Copy link
Member

@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?

@dotnetjunkie
Copy link
Author

Hi @javiercn, thank you for your comment.

Is there something you could do by adding a circuit handler and calling an API on your container to set the scope?

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.

@mkArtakMSFT mkArtakMSFT added this to the Next sprint planning milestone Jan 13, 2021
@ghost
Copy link

ghost commented Jan 13, 2021

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@SteveSandersonMS SteveSandersonMS added affected-very-few This issue impacts very few customers enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-major This label is used by an internal tool labels Jan 26, 2021 — with ASP.NET Core Issue Ranking
@ghost
Copy link

ghost commented Jul 20, 2021

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.

@mkArtakMSFT
Copy link
Member

Hi. Thanks for contacting us.
We're closing this issue as there was not much community interest in this ask for quite a while now.
You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-very-few This issue impacts very few customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-server investigate severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

5 participants