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

Challenges in using WebApplication.CreateEmptyBuilder #59437

Open
kikaragyozov opened this issue Dec 11, 2024 · 2 comments
Open

Challenges in using WebApplication.CreateEmptyBuilder #59437

kikaragyozov opened this issue Dec 11, 2024 · 2 comments
Assignees
Labels
area-hosting Includes Hosting Docs This issue tracks updating documentation
Milestone

Comments

@kikaragyozov
Copy link

kikaragyozov commented Dec 11, 2024

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Dec 11, 2024
@mkArtakMSFT mkArtakMSFT added area-hosting Includes Hosting Docs This issue tracks updating documentation and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Dec 11, 2024
@mkArtakMSFT
Copy link
Member

@eerhardt given that you've worked on some of this relatively recently, would you be open to documenting these two new APIs so that questions like these are addressed in docs?

@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Dec 11, 2024
@eerhardt
Copy link
Member

We have the differences between the 3 APIs documented here:

https://review.learn.microsoft.com/en-us/aspnet/core/fundamentals/native-aot?view=aspnetcore-9.0&branch=main#createslimbuilder-vs-createbuilder

Which links out to https://andrewlock.net/exploring-the-dotnet-8-preview-comparing-createbuilder-to-the-new-createslimbuilder-method/, another great piece of information.

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 not sure starting from "empty" is the best route in your case. If you want mostly the default behavior, minus one thing, it would be better to take the route of removing that one thing. In your case it sounds like you want to remove a configuration source from the ConfigurationManager. You can do this by calling builder.Configuration.Sources.Remove to remove the one you don't want, and then add what you want back in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-hosting Includes Hosting Docs This issue tracks updating documentation
Projects
None yet
Development

No branches or pull requests

3 participants