I'm writing a service in Nancy and I'm using some middleware for monitoring the service:
app.UseOwin(buildFunc =>
{
var log = ConfigureLogger();
buildFunc.UseMonitoringAndLogging(log, HealthCheck);
buildFunc.UseNancy();
});
The middleware is configured to use a HealthCheck() function defined in the Startup class as:
public async Task<bool> HealthCheck()
{
return await SomeRepo.HealthCheck();
}
SomeRepo has a HealthCheck() method that queries the database to confirm it is available/responding. But how to inject SomeRepo into the Startup class, or alternatively access the container to resolve SomeRepo?
At this point you are still in Owin and not in the Nancy pipeline. What host are you running on ? If you are using
aspnetcorethe you can register your deps inRegisterServices()method and it will handle the injection into your method. You can useAutofacorStructureMapso you can share your container with Nancy as well like this.