Skip to content
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

Add WebApplication.CreateEmptyBuilder #49246

Merged
merged 4 commits into from
Jul 13, 2023

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Jul 6, 2023

Allow an empty WebApplicationBuilder to be created without default behavior. There is no default configuration sources (ex. environment variables or appsettings.json files), no logging, and no web server (ex. Kestrel) configured by default. These can all be added explicitly by the app.

The following middleware can be enabled by the app:

  • Routing and Endpoints, if the app calls Services.AddRouting, and then MapXXX or registers an EndpointDataSource manually
  • AuthN/Z, if the app adds the corresponding Auth services

Fix #48811

cc @DamianEdwards @davidfowl

@ghost ghost added the area-hosting Includes Hosting label Jul 6, 2023
Allow an empty WebApplicationBuilder to be created without default behavior. There is no default configuration sources (ex. environment variables or appsettings.json files), no logging, and no web server (ex. Kestrel) configured by default. These can all be added explicitly by the app.

The following middleware can be enabled by the app:

- Routing and Endpoints, if the app calls MapXXX or registers an EndpointDataSource manually
- AuthN/Z, if the app adds the corresponding Auth services
- HostFiltering and ForwardedHeaders

Fix dotnet#48811
@eerhardt eerhardt force-pushed the EmptyWebApplication branch from 933bdee to 5cf2861 Compare July 6, 2023 19:43
Remove Routing from the "Empty" builder. It is up to the app to configure what they want. This is the Empty WebApplication.
Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only thing that really needs to be addressed before merging is the hosting startup stuff when configured via the command line.

src/DefaultBuilder/src/WebApplicationBuilder.cs Outdated Show resolved Hide resolved
_genericWebHostServiceDescriptor = InitializeHosting(bootstrapHostBuilder);
}

internal WebApplicationBuilder(WebApplicationOptions options, bool slim, bool empty, Action<IHostBuilder>? configureDefaults = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We only have two remaining readonly fields. Is it time to make those non readonly (and possibly "lie" about the nullability), give these more logical method names and remove the weird bool args. E.g. InitializeEmpty, InitializeSlim, InitializeFull?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's consider this in a future change. I'm not excited about the factoring now, but it can easily be changed later without breaking anyone.

Respect hosting startup configuration. Refactor to share logic.
@eerhardt eerhardt enabled auto-merge (squash) July 12, 2023 23:32
@eerhardt eerhardt merged commit bad8559 into dotnet:main Jul 13, 2023
@ghost ghost added this to the 8.0-preview7 milestone Jul 13, 2023
@eerhardt eerhardt deleted the EmptyWebApplication branch July 13, 2023 14:26
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-hosting Includes Hosting area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow empty WebApplicationBuilder to be created without default behavior
7 participants