I am being asked to develop a layer that will act as a generic bus without any direct references to NServiceBus. Which so far thanks to support for unobtrusive messages isn't too hard. Except now I've been asked to provide our own definition for IHandleMessages and find a way to map it during wireup. So I'm thinking something like this:
public class MessageHandlerAdapter<T> : IHandleMessages<T>
{
IUnityContainer container;
public MessageHandlerAdapter(IUnityContainer container)
{
this.container = container;
}
#region IMessageHandler<T> Members
public void Handle(T message)
{
var handler = container.Resolve<IHandle<T>>();
handler.Handle(message);
}
#endregion
}
Where IHandle would be our own definition (which by the way is exactly the same as IHandleMessages). I would expect to reflect over the AppDomain and find all classes that implemented IHandle and Register them with the container, then register a MessageHandlerAdapter with the same type T.
My problem is I haven't used NServiceBus for almost 2 years and I don't remember where to hook into this kind of functionality in the NSB pipeline.