dotnet-architecture / HealthChecks

Experimental Health Checks for building services, such as with ASP.NET Core
Other
453 stars 124 forks source link

HealthChecks functions should be passed a ServiceScope #69

Closed matthewDDennis closed 7 years ago

matthewDDennis commented 7 years ago

I am trying to implement a DbContext health check. The Sql health check doesn't work for me as I could be using any of a number of database providers such as PostgreSQL.

However, the check function needs a scoped instance of the DbContext to test, and this is not available during the Startup.ConfigureServices method.

If the HealthCheckServices passed in the IServiceScope, then the check method could get any services it required using IServiceScope.ServiceProvider.

matthewDDennis commented 7 years ago

Found out the way to do it. Use the AddCheck<DbConetextChecker> method where the DbConetextChecker constructor has an IServiceScope parameter. The type gets resolve at execution time.