Start Debugging

dotnet-10

128 posts · Page 2 of 13

How to initialize interdependent async singletons at startup in ASP.NET Core

Give each singleton a memoized InitializeAsync that awaits its own dependencies, then await them all from IHostedLifecycleService.StartingAsync. Registration order stops mattering, Kestrel does not accept requests until init finishes, and a failure stops the host. Compared against init before app.Run, IHostedService.StartAsync, and a BackgroundService with a readiness check on ASP.NET Core 10.0.10.
Prev Next