-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Allow empty WebApplicationBuilder to be created without default behavior #48811
Comments
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
API Review Notes
We want all the features listed to be ❌ except command line args which are already effectively opt-in API Approved! namespace Microsoft.AspNetCore.Builder
{
public class WebApplication
{
+ public static WebApplicationBuilder CreateEmptyBuilder(WebApplicationOptions options);
}
} |
#48956 would also benefit from this. |
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
* Add WebApplication.CreateEmptyBuilder 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 * Remove Routing from the "Empty" builder. It is up to the app to configure what they want. This is the Empty WebApplication. * Respect hosting startup configuration. Refactor to share logic.
Background and Motivation
The default host builder pulls in a ton of dependencies that are rooted for trimming by default. With #32485 we added
CreateSlimBuilder
, which reduced the set of dependencies, but still brought some default dependencies in - for example #47664 brought in AuthN/Z and #47797 brought back in appSettings.json and logging.We should implement the original proposal in #32485 and make a WebApplicationBuilder that doesn't have any default behavior - i.e. "empty".
Proposed API
namespace Microsoft.AspNetCore.Builder { public class WebApplication { public static WebApplication Create(string[] args); public static WebApplicationBuilder CreateBuilder(); public static WebApplicationBuilder CreateBuilder(string[] args); public static WebApplicationBuilder CreateBuilder(WebApplicationOptions options); public static WebApplicationBuilder CreateSlimBuilder(); public static WebApplicationBuilder CreateSlimBuilder(string[] args); public static WebApplicationBuilder CreateSlimBuilder(WebApplicationOptions options); + public static WebApplicationBuilder CreateEmptyBuilder(WebApplicationOptions options); } }
Usage Examples
Features
When creating an "empty" web application, the following features will be on (✅) or off (❌) by default. Note that these features can be enabled by the app explicitly after creating the builder/application. They just won't be enabled by default.
Alternative Designs
We could add all 3 overloads for
CreateEmptyBuilder
. But I don't see the need to make it super easy to use this API.Risks
It may be confusing which builder to use in your app.
The text was updated successfully, but these errors were encountered: