Workaround assembly scanning, feasible?

While liking NServiceBus and it’s easyness a lot, there is one thing I completely misslike. This is the build-in, hard coded assembly scanning that is very eager by default. In general I see the point of doing the scanning for keeping things simple. On the other hand, offering the possibility to ‘hi-jack’ an entire process by simply putting a dll into the correct directory makes me shiver.

So I gave some thoughts how I could prevent scanning of anything but the original NServiceBus assemblies and write a DI (autotac) extension that forces me to explicitly register my handlers when my container is built. So I came up with configuring the scanning process to ignore all assemblies in my bin except the NServiceBus ones. In my container extension I added a method ‘RegisterMessageHandler’ which internally registers the type in the container and additionally sets up a callback to register the type with the ‘MessageHandlerRegistry.RegisterHandler(typeof(T))’ when the container is built. This actually seems work pretty well, but I wonder if that could have side effects I did not yet encounter?

I’m aware that this tightly couples my container extension to the internas of NServiceBus.Core (there if no interface for taht service), but I feel like it’s an isolated dependency that could be adapted in a single place if the internas of NServiceBus would change for registering handlers.

I would be thankfull for any thoughts or comments on this approach.

Hi Urs

One of the thing you need to take into account as well is that NServiceBus assembly scanning not only discovers handles and sagas but also other related functionality like Installers, Initializers and Features (I might have forgotten one or another).

In general, we are trying to make sure that if our components rely on features they are registered properly without relying too much on the scanning magic but I don’t think that there is any guarantee that you might not run into problems with a component that happens to assume scanning will discover the feature magically.

Regards
Daniel