NServiceBus
                                
                                
                                
                                    NServiceBus copied to clipboard
                            
                            
                            
                        Dependency injection friendly way to be able to send message in and outside an incoming message context with and without outbox
Currently, there is IMessageSession which is not context aware and there is IMessageHandlerContext.
- 
IMessageHandlerContextisn't registered in the incoming message DI context. This makes it impossible for users that use for example the service or repository like patterns to have any layers not take a dependency onIMessageHandlerContextas that must currently be propagated as an argument. - 
Even if
IMessageHandlerContextis registered in the DI container this is not availabe outside a incoming message context like nested code that is invoked via a web API that somewhere sends a message. 
Users that have code that needs to send message in both scenarios currently don't have a easy way of doing this.
NServiceBus.UniformSession could be used but that solution does not work for users that would want to use outbox. Recently NServiceBus.TransactionalSession is created but unfortunately, both are not compatible.
If code will always be using Outbox then likely eventually NServiceBus.TransactionalSession could be extended so that the interface can also be used via dependency injection in an incoming message context. However, this is not a guarantee and to me it feels this DI use case should already be part of Core.
Maybe NServiceBus.UniformSession can somehow be embedded into core where an message operations interface or session interface is shared with TransactionalSession to control a unit of work which potentially can share its atomic or transactional storage context.