As far as I know, the ActivatorUtilities.CreateInstance is supported inside asp.net 6.
You could directly use it inside the asp.net6 program.cs. ASP.NET6 unifies Startup.cs and Program.cs into a single Program.cs file.
As you mentioned, the app.ApplicationServices is not existed inside asp.net 6, we should use app.Services instead.
The code like below:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
await ActivatorUtilities.CreateInstance<DatabaseInitializer>
(app.Services).Initialize();
app.UseHttpsRedirection();
app.UseStaticFiles();
//app.UseAuthentication();
app.UseRouting();
//app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();