I just set this up for a proof of concept because I use the following convention per the Microsoft CQRS Journey guidelines:
I wanted use the IOC container's (SimpleInjector) API to enforce the convention as it forces you to make single vs multi handlers registrations explicit by design. Now, my IOC container will throw an Exception anytime two handlers for the same command are accidentally registered.
To get MemBus to support this convention, I needed to create my own ISetup, ISubscriptionResolver, and IoCAdapter (starting with the code from IoCSupport, IoCBasedResolver, and IocAdapter respectively). I also had to create a new IocAdapter interface that also supports the singular GetInstance() method; now the interface roughly matches the System.Web.Http.Dependencies.IDependencyScope interface (GetService and GetServices).
// Setup
return BusSetup
.StartWith<Conservative>()
.Apply<CommandingEventingSupport>(
adapter =>
{
adapter.SetAdapter(new MemBusSimpleInjectorAdapter(container));
adapter.SetCommandHandlerInterface(typeof(IHandleCommand<>));
adapter.SetEventHandlerInterface(typeof(IHandleEvent<>));
adapter.SetCommandTest(obj => obj is IDomainCommand);
})
.Construct();
And then the resolver dispatches commands to the GetInstance and events to GetAllInstances...
// Command vs Event
public IEnumerable<ISubscription> GetSubscriptionsFor(object message)
{
bool isCommand = _isCommandFunc(message);
Type typeToCreate = isCommand
? _commandHandlerType
: _eventHandlerType;
var handlesType = ConstructHandlesType(typeToCreate, message.GetType());
var mi = handlesType.GetRuntimeMethods().First();
return isCommand
? new[] { mi.ConstructSubscription(_adapter.GetInstance(handlesType)) }
: _adapter.GetAllInstances(handlesType).Select(mi.ConstructSubscription);
}