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.