ASP.NET Core 6.0 introduces a new minimal hosting model: https://learn.microsoft.com/en-us/aspnet/core/migration/50-to-60-samples?view=aspnetcore-6.0
After switching to the minimal hosting model, I wonder how to migrate the IWebHost
building to be compatible with the new minimal hosting model.
Sample how we are currently building our IWebHost
for integration tests (.NET 5):
ServiceDescriptor[] grabbedServices = null;
var host = new WebHostBuilder()
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostingContext, config) =>
{
//some configuration here
})
.UseDefaultServiceProvider(x => x.ValidateScopes = true)
.ConfigureTestServices(services => { grabbedServices = services.ToArray(); })
.Build();
As after switching to minimal hosting model we do not have Startup
anymore, this does not compile.
I sense that we should replace the UseStartup<Startup>
part with Configure
? If so, what's the correct way how to construct the IApplicationBuilder
?
Maybe there is some other way to build IWebHost
?