Open
Description
Describe the bug
This issue is about a very hidden behaviour when DeferredHostBuilder is being used.
I came across this issue when fixing an issue with databases being seeded twice during tests:
https://github.com/ardalis/CleanArchitecture/pull/277/files
The reason is that in contrast to other IHostBuilder implementations DeferredHostBuilder actually does start the Host when calling:
IHostBuilder builder;
builder.Build();
Since this is also done on a separate thread this leads to race conditions in code that previously didn't have them. The issue comes up when switching to the new template for aspnetcore servers that don't use a Startup class
To Reproduce
- Create an aspnetcore 6.0 project without a Startup class
- Create a CustomWebApplicationFactory extending WebApplicationFactory
- Override CreateHost(IHostBuilder builder)
- Call
builder.Build()
then perform other things with the host's services - Notice that the code in Program.cs is running in parallel and you might be getting race conditions now
Exceptions (if any)
Further technical details
- ASP.NET Core version: 6.0.100
- The IDE (VS / VS Code/ VS4Mac) you're running on, and its version: dotnet-cli 6.0.100