Closed cocosip closed 4 years ago
You should move your initialization code to either Main
or ConfigureServices
.
This is intentional. With the move to the generic host in 3.x the web service is now an IHostedService just like BackgroundService. Those run in the order they're registered. If you register your HostService1 in Program.cs before the web service you should see the order swap.
The delay to run Configure during StartAsync is also intentional. We found too many apps were running things like database migrations during Configure. There are tools that build the host to get access to services but they never start the host. Those tools did not want to run full app setup logic, only get the services.
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.
Describe the bug
When i use
BackgroundService
in Asp.Net Core 3.1 project, i find that theSetup
Configure
method will execute afterBackgroundService
ExecuteAsync
method. There are some initialize code inConfigure
method, so whenBackgroundService
have some injections, it will caught some exception.To Reproduce
Exceptions (if any)
Further technical details
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]