How to unify IMessageHandlerContext and IMessageSession

I understand, that it is recommended to use IMessageHandlerContext, when sending further messages within a handler, to make sure that those messages participate in the same transaction scope. Our feature module used in the message handler which sends further messages, is used in a API as well. In the case, where we use the feature module from the API, the module should not use IMessageHandlerContext (because it doesn’t exist) but either IEndpointInstance or IMessageSession. The early versions of NSB provided a unified interface (IBus). With the seperation of these two use cases, we have to duplicate the interfaces. I understand that IMessageHandlerContext provides more properties and methods because it is used within a handler, but i in most cases, i think people don’t need to access message headers and more. Is there a way (unified interface), which fits both IMessageSession and IMessageHandlerContext? I think IUniformSession is not an option, because we use poor mans DI without any container.

Thanks in advance

NSB Version: 6.4

Hi Fabian,

as you already mentioned in your question the move to have two separate interfaces was mean to make sure users are clear in terms of what is possible and what are the guarantees when sending messages inside and outside of a handler. You can find detailed descriptions of the reasoning here: Moving away from IBus in Version 6 • NServiceBus • Particular Docs.

The IUniformSesions was meant to make it easier for our users to migrate from the IBus interface by providing an intermediate step towards the two interfaces. So I would not recommend using it for newly created systems which is your case if I understand correctly.

Could you share more information on the code duplication aspect that you are mentioned?

Regards,
Tomasz