【发布时间】:2016-07-31 17:45:14
【问题描述】:
我正在尝试装饰我的命令处理程序,并且我正在尝试在我的处理器中解决它们。
我这样注册我的命令:
builder.RegisterAssemblyTypes(typeof(ICommandProcessor).Assembly)
.AsClosedTypesOf(typeof(ICommandHandler<,>))
.AsSelf().AsImplementedInterfaces().Named("implementor", typeof(ICommandHandler<,>));
builder.RegisterGenericDecorator(
typeof(CatchValidationErrorsDecorator<,>),
typeof(ICommandHandler<,>), fromKey: "implementor")
.AsImplementedInterfaces();
问题是当我不使用命名扩展时,通用装饰器不起作用。 当我使用命名扩展时,我无法像这样解析我的组件:
var handerType = typeof (ICommandHandler<,>)
.MakeGenericType(command.GetType(), typeof (TResult));
dynamic handler = _container.Resolve(handerType);
有人知道如何解决这个问题吗?
【问题讨论】:
标签: c# autofac command-pattern