I am trying migration source code of a ASP.NET Core 3.x to version 6.x . Source code
How to fix?
CodePudding user response:
You can't inject services in Program.cs
using constructor. This is where the application starts, dependency injection container is not created yet. Instead you can access configuration using builder.Configuration
:
var builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<AppSettings>(builder.Configuration.GetSection("AppSettings"));
var app = builder.Build();