dotnet / dotnet/aspnetcore

Challenges in using WebApplication.CreateEmptyBuilder

Open
#59,437 8 comments 0 reactions 1 assignee Claimed by @eerhardt View on GitHub
area-hosting Docs
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

Having the ability to create an empty builder is amazing, but if my use-case is rather simple - I have to alter the way configuration is loaded into an ASP.NET Core project, for example due to encryption being involved, which basically means using `AddJsonStream` instead of the default - I'm left with a dozen of questions.

What must I call to achieve the same behavior I was previously getting with the default builder minus X?

I'm left to my own devises, having to scrape what code was added in PRs like #47797 and having to inspect code like [HostingBuilderExtensions](
https://github.com/dotnet/runtime/blob/6149ca07d2202c2d0d518e10568c0d0dd3473576/src/libraries/Microsoft.Extensions.Hosting/src/HostingHostBuilderExtensions.cs#L266) and other parts here and there, leading to a chaotic experience and definitely missing something somewhere between the lines.

There also appears to be zero official documentation regarding proper usage of `CreateEmptyBuilder`, or what features it still supports out of the box. The closest thing to a documentation regarding the features set, could be seen in #48811

For example, currently, I'm unsure if I am to do
```
builder.Services.AddLogging(logging =>
{
logging.AddConfiguration(configuration.GetSection("Logging"));
logging.AddConsole();

logging.Configure(options =>
{
options.ActivityTrackingOptions =
ActivityTrackingOptions.SpanId |
ActivityTrackingOptions.TraceId |
ActivityTrackingOptions.ParentId;
});
});
```
versus a simple
```
builder.Logging
.AddConfiguration(builder.Configuration.GetSection("Logging"))
.AddConsole();
```

There's also no guarantee that in doing this approach, I'll always get the same expected behavior, as the code for the default behavior can change with time, which would render the one I copied to try and "mimic" it invalid.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.