As far as I can tell, they replaced it with a concrete instance of ConfigurationManager class which is a property of the WebApplicationBuilder.
In your Program.cs class there is a line of code:
var builder = WebApplication.CreateBuilder(args);
You can then access the configuration from this builder instance:
builder.Configuration.GetConnectionString("DefaultConnection");
I know this does not answer your "how to inject IConfiguration" question but I'm guessing you just want to be able to access your configuration settings. There is nothing stopping you from setting up the project as it used to be in the old .net 5 code. All you need is Program.cs to be:
public class Program
{
public static async Task Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
await host.RunAsync();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Trace);
});
});
}
And then just create a class called Startup.cs with the following code:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
private IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
// TODO: Service configuration code here...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// TODO: App configuration code here...
}
}
UseStartup
seems to still exist in ASP.NET Core 6, though I haven't yet updated to VS2022 so I can't test. – Hypersensitive