Delay dashboard initialization

Hello!

Setting up the dashboard in an ASP.NET Core application works with app.UseHangfireDashboard(). This requires Hangfire to be set up properly and the database to be accessible.

My application with Hangfire runs in Kubernetes and I want to implement the readiness probe. The condition for this probe is that the service can be started and is available independent of external required services, like the database. In short, starting the service without database should work. But UseHangfireDashboard() requires the database to be there.

Is there a way to defer the initialization until a check says, that the database is there?

I tried with a startup service. But the general issue is that when I pass the WebApplication instance to it I can run app.UseHangfireDashboard(), but it has no effect. Most likely because the application is already running and the change has no effect.

Using middleware or host application fails with not being able to inject the IApplicationBuilder.

Any help or hints into the right direction are very much appreciated - thanks!