我有这样的命令:
public class EditComplaintCommandHandler : IHandleCommand<EditComplaintCommand>
{
private readonly IUnitOfWork _unitOfWork;
public EditComplaintCommandHandler(
IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public void Handle(EditComplaintCommand command)
{
// do stuff
}
}
现在我只想装饰这个命令。这是我的装饰师:
public class MySpecificCommandDecorator : IHandleCommand<EditComplaintCommand>
{
private readonly IUnitOfWork _unitOfWork;
public MySpecificCommandDecorator(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public void Handle(EditComplaintCommand command)
{
// do something
}
}
所以我希望MySpecificCommandDecorator
仅装饰EditComplaintCommandHandler
。
我试过了:
builder.RegisterAssemblyTypes(assemblies)
.AsClosedTypesOf(typeof(IHandleCommand<>))
.Named("handler", typeof(IHandleCommand<>));
builder.Register(c => new MySpecificCommandDecorator(c.Resolve<IUnitOfWork>()))
.As<IHandleCommand<EditComplaintCommand>>();
但这并不适用,因为我没有将它注册为装饰者。
如何使用Autofac仅使用EditComplaintCommandHandler
装饰MySpecificCommandDecorator
?