Closed alexdrl closed 6 years ago
Rebus requires its container adapters to throw an InvalidOperationException
if the bus is configured twice with that container.
The reason is that it automatically registers IBus
, ISyncBus
, and IMessageContext
in containers, and it would lead to ambiguous code and hard to debug errors if you then simple had IBus
injected into your class without specifying which bus.
Moreover, I have often experienced people thinking that they should register multiple buses e.g. in order to host multiple endpoints within the same process, but if that's the goal, then it's better to simply new up multiple containers.
I've read the code of the 'AddRebus' method, and throws an InvalidOperationException if the IBus interface is already registered.
What is the reasoning behind this? Some .NET Core libraries allow this, without throwing exceptions.
Also, if the problem is about re-registering something, you could try to register only once with the TryAdd method...