需要使用Unity DI实施命令处理程序/总线的帮助 [英] Need help implementing Command Handlers/Bus using Unity DI

查看:89
本文介绍了需要使用Unity DI实施命令处理程序/总线的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,
我正在尝试通过命令和命令总线将旧的棕地应用程序重构为CQRS体系结构,以进行域修改。



应用程序很可能会在Asp.Net MVC3中实现。我的雇主更喜欢在MVC应用程序中使用Unity for DI。



我可以找到显示用于命令/总线解析的依赖容器的任何示例都是基于Structuremap或Autofac的。在此实现中,我将需要使用Unity。有没有人以这种方式使用Unity或知道任何示例?

解决方案

您认为您到底在哪里需要容器?也许这篇文章包含一些有用的信息。



它描述了处理命令的容器不可知方式。






更新



您的意思是您想要这样的东西:

  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);

该注册使用Unity的自定义配置引擎,该引擎提供了StructureMap的配置的许多功能。 / p>




Update2



代码样本是我的 codeplex上的宠物项目的一部分。以上代码段可以在 TecX.Unity.Configuration.Test 项目中找到。


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.

这篇关于需要使用Unity DI实施命令处理程序/总线的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆