Skip to content

Challenges in using WebApplication.CreateEmptyBuilder #59437

Open
@kikaragyozov

Description

@kikaragyozov

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 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.

Metadata

Metadata

Assignees

Labels

DocsThis issue tracks updating documentationarea-hostingIncludes Hosting

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions