Custom checks in library

Hi,

Our teams are looking to use custom checks as part of our monitoring strategy. We would however like to create our own library of “checks” so that we don’t have to copy-and-paste the checks into various projects.

The issue is, we would need to configure the checks with values associated to that team only. A simple example would be that the projects need to perform a check for SQL server, however, the connection string between the teams are different.

Therefore, I’d like to manually register the health checks and not rely on assembly scanning to register said checks and this is exactly where I’m stuck.

Any guidance / advice on how this can be achieved?

Good day @Ruaan,

and welcome to the Particular discussion group.

What you’re trying to achieve is not supported out of the box. However, it can be achieved by:

  • disabling assembly scanning for the custom checks types you need to manually configure (or if it’s easier for the entire assembly containing those types).
  • manually registering custom checks types into the IoC container.

The only requirement is to not use the default built-in NServiceBus container, or in general to not use the NServiceBus DI (IContainer) API to register types. For historical reasons the IContainer API won’t register the same interface multiple times so, only one custom check will be registered.

There is an issue on the docs repository that discusses a similar problem, I posted there a sample solution that uses the IServiceCollection/IServiceProvider external container support, it should work for any other container supported by NServiceBus.

Hope this helps, regards.
.m

1 Like

Thank you @mauroservienti!

I’m going to try the solution in the link posted and will provide feedback :slight_smile:

Hi @mauroservienti, based on your example I was able to get it working. Thank you so much for the help and advice!

That’s good to hear @Ruaan, thanks for the feedback.