Is the IMessageHandlerContext exclusive to every handler/endpoint?

Hi,
I am trying to create an interface to publish events that can be used from different places in the application to publish events.

Given that one of the potential places to be used are the handlers, and events in handlers according to the documentation have to be dispatched using the IMessageHandlerContext , I think I will need a method like this one:

Task Publish(IMessageHandlerContext context, IMyEvent event);

The problem is that this interface will be used from projects that do not have the reference to Nservicebus, and the presence of the context parameter in the method is a bit of an inconvinient , because I would have liked to avoid to tightly coupling the project to the Nservicebus library.

One thing that I have seen done to avoid this issue is to rewrite the interface method to this:

Task Publish(IMessageHandlerContext context, IMyEvent event);

And have the implementation to be a singleton like this:

public class MyMessagingService: IMyMessagingService{
public IMessageHandlerContext  Context {get;set;}

Task Publish(IMessageHandlerContext  context, IMyEvent event){

}
}

And set the Context using for example interceptors (every time a handler is called itis intercepted and the Context property set).

I am a bit concerned, though, of what can happen if I have multiple concurrent request, where for example a handler sets the context, and before it is processed a different handler pops and updates the context,so that now the event in handler A is published using the context in handler B.

Would that cause any trouble? or is the IMessageHandlerContext shared for all the handlers in an endpoint? What about different end points in the same solution?

Is a more standard practice to approach this issue, or was the whole interface to centralize managing of messages a bad idea to start with?

Thank you for your help.

You are right that you should worry about concurrency as IMessageHandlerContext is not a singleton and applies to an specific incoming message.

Maybe the Uniform Session is useful for you?

I would recommend to not make an additional abstraction on top of the IMessageSession or IMessageHandlerContext abstractions.