Use unified container between Uno & Maui #1933
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GitHub Issue (If applicable): #
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Uno's Host Builder and the MauiAppBuilder provide 2 separate instances of the IServiceProvider each with their own registered services. This means that services registered in one cannot be properly resolved by the other.
What is the new behavior?
Both builders have an IServiceProviderFactory. When using the IHostBuilder the initialization of the MauiAppBuilder is deferred so that all Services can be registered with both the HostBuilder's IServiceCollection and the MauiAppBuilder.Services. The two are combined and an IServiceProvider is created. This IServiceProvider is then shared with .NET MAUI so that both Uno and .NET MAUI can make use of the same container with all of the same services available to each.
NOTE In testing the only "Duplicated" Service out of the box is IConfiguration. To prevent this from being an issue when we combine the two IServiceCollection's we use TryAdd. This prevents the addition of a ServiceDescriptor from the .NET MAUI side with a ServiceType that has already been provided on the Uno side.