Skip to content

Observe more mutations to configuration and services #34615

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

Merged
merged 4 commits into from
Jul 24, 2021

Conversation

davidfowl
Copy link
Member

  • When using WebApplicationFactory with the WebApplicationFactory, mutations are made very late that aren't observable via the WebApplicationBuilder.Configuration nor WebApplicationBuilder.Services. The configuration tries to be the source of truth but more sources are added it can't see, the same with the service collection (though that is more rare). To fix this, the strategy is to use the initial service collection and configuration as data that will feed into the final IConfigurationBuilder and IServiceCollection, and then "update" these properties to point back to the final configuration and service collection. Results in the properties on the builder being consistent (from a data POV) with the built application.
  • Added tests that mimic what the WebApplicationFactory does but using the diagnostic source to capture the right events for the right host and mutate the IHostBuilder.

Fixes #33876

@davidfowl davidfowl requested a review from Tratcher as a code owner July 22, 2021 07:55
@ghost ghost added the area-runtime label Jul 22, 2021
@davidfowl davidfowl requested a review from halter73 July 22, 2021 07:55
- When using WebApplicationFactory with the WebApplicationFactory, mutations are made very late that aren't observable via the WebApplicationBuilder.Configuration nor  WebApplicationBuilder.Services. The configuration tries to be the source of truth but more sources are added it can't see, the same with the service collection (though that is more rare). To fix this, the strategy is to use the initial service collection and configuration as data that will feed into the final IConfigurationBuilder and IServiceCollection, and then "update" these properties to point back to the final configuration and service collection. Results in the properties on the builder being consistent (from a data POV) with the built application.
- Added tests that mimic what the WebApplicationFactory does but using the diagnostic source to capture the right events for the right host and mutate the IHostBuilder.
@davidfowl davidfowl force-pushed the davidfowl/single-source-of-truth branch from fff7cd1 to 4029641 Compare July 24, 2021 07:38
Register servers to avoid double adding the GenericWebHostService
@davidfowl davidfowl enabled auto-merge (squash) July 24, 2021 08:49
@davidfowl davidfowl merged commit d434b1c into main Jul 24, 2021
@davidfowl davidfowl deleted the davidfowl/single-source-of-truth branch July 24, 2021 21:30
@ghost ghost added this to the 6.0-rc1 milestone Jul 24, 2021
@amcasey amcasey added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-hosting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebApplication does not observe changes made with WebApplicationFactory<T> in tests
3 participants