Folks, I am trying to re-factor a legacy brownfield application into a CQRS architecture with commands and a command bus for domain modifications.
The application will more than likely be implemented in Asp.Net MVC3. My employer prefers the use of Unity for DI in MVC applications.
Any examples I can find showing a dependency container for command/bus resolution are based on Structuremap or Autofac, however I will need to use Unity in this implementation. Has anyone used Unity in this manner or know of any examples?
Where exactly do you think you need the container at all? Maybe this post contains some usefull information.
It describes a container agnostic way of handling commmands.
Update
You mean you would like to have something like this:
var builder = new ConfigurationBuilder();
var convention = new CommandHandlerConvention().WithTransaction().WithDeadlockRetry();
builder.Extension<DecoratorExtension>();
builder.Scan(x =>
{
x.With(convention);
x.AssemblyContainingType(typeof(BarCommand));
});
var container = new UnityContainer();
container.AddExtension(builder);
ICommandHandler<BarCommand> barHandler = container.Resolve<ICommandHandler<BarCommand>>("BarHandler");
var command = new BarCommand();
barHandler.Handle(command);
Assert.AreEqual("-->Retry-->Transaction-->BarHandler", command.HandledBy);
That registration uses a custom configuration engine for Unity that provides a lot of the features of StructureMap's config.
Update2
The code samples are part of my pet project on codeplex. The above snippets can be found inside the TecX.Unity.Configuration.Test project.
ICommandHandler<T>
and IEventHandler<T>
. The manual wiring is simply too painful. So the OPs question remains: how to do this with Unity - Steven 2012-04-04 07:29
ConfigurationBuilder
, CommandHandlerConvention
, and DecoratorExtension
part of Unity? If not, where are they from - Steven 2012-04-04 11:25