ConfigureServices registers the app's services with the dependency injection container. The host calls it before Configure, so every service it adds is ready when the request pipeline is built.
Framework features such as MVC, Razor Pages and Entity Framework Core register through Add{Service} extension methods, like AddControllersWithViews and AddDbContext. Your own services go in the same place, each with a lifetime set by AddTransient, AddScoped or AddSingleton. Configuration options are usually set here too.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
In .NET 6 and later templates there is no ConfigureServices method. The same registrations go on builder.Services in Program.cs, before builder.Build().
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓