[Blazor] Platform Initialization strategy around services within different Blazor flavors
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
There are a bunch of services we require initialization for in different platforms:
* NavigationManager
* AuthenticationStateProvider
* ComponentApplicationLifetime
Every time we are in this situation we have to be making changes on each platform "host" to include code specific to those services.
In addition to that, third-party components need to come up with their own strategy around how they initialize services.
As we add more services, this doesn't really scale up. The proposal here is to provide a new primitive that we use and that third-party code can use too to initialize their components. We will move our own initialization code to use this new primitive and enable third-party customers/libraries to also implement it.
The way this works at a high level is:
* We will provide an "Initializer" interface that we will resolve from DI.
* Our TContext will be what the host platform passes to the initializer. In the three cases we care about right now:
* HttpContext -> For when we are doing prerendering.
* Circuit -> For when we are rendering Blazor server.
* WebAsemblyHost -> For when we are rendering on a webassembly context.
Blazor desktop will likely be a 4th option on the list above.
During initialization we will resolve a list of all the Initializers and run them in order (order is important here because they can have service dependencies between them (I actually run into this at one point with auth and NavigationManager))
As an addendum to this issue, we want to support also initialization on the JS side of things:
* Loading library scripts at the right time.
* Configuring how Blazor wasm/server JS options.
* Customizing Blazor wasm boot process
Contributor guide
Assessment
This issue has not been assessed yet.