Skip to content

Fixer/Analyzer: Suggest switching builder.Host.ConfigureAppConfiguration and builder.Host.ConfigureHostConfiguration to use the builder.Configuration property directly #35815

Closed
@davidfowl

Description

@davidfowl

The WebApplicationBuilder has top level properties to remove some of the callback noise and we should push developers towards using those properties in their code since they are the moral equivalent to the Configure* callbacks:

var builder = WebApplication.CreateBuilder(args);

builder.Host.ConfigureAppConfiguration(builder =>
{
    builder.AddJsonFile("foo.json", optional: true);
});

// OR

builder.Host.ConfigureHostConfiguration(builder =>
{
    builder.AddJsonFile("foo.json", optional: true);
});

// OR

builder.WebHost.ConfigureAppConfiguration(builder =>
{
    builder.AddJsonFile("foo.json", optional: true);
});

Should be rewritten to:

var builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddJsonFile("foo.json", optional: true);

Metadata

Metadata

Assignees

Labels

Priority:2Work that is important, but not critical for the releaseanalyzerIndicates an issue which is related to analyzer experiencearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-hostingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions