我使用基於此Link的CQRS並使用SimpleInjector來啓動裝飾器。但他們沒有被解僱。我在這裏做錯了什麼?SimpleInjector - 裝飾者不開火?
這裏是我的ICommandHandler部分:
public interface ICommandHandler<TCommand> where TCommand : Command
{
void Handle(TCommand command);
}
public interface ICommandHandler<TCommand, TResult> : ICommandHandler<TCommand>
where TCommand : Command<TResult>
{
}
而且BaseCommandHandler部分:
public abstract class BaseCommandHandler<TCommand>
: ICommandHandler<TCommand> where TCommand : Command
{
public DbEntities Db { get; set; }
public BaseCommandHandler(DbEntities db)
{
Db = db;
}
public BaseCommandHandler() : this(new DbEntities())
{
}
public abstract void Handle(TCommand command);
}
public abstract class BaseCommandHandler<TCommand, TResult>
: BaseCommandHandler<TCommand>
where TCommand : Command<TResult>
{
}
SimpleInjector配置:
container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>),
typeof(BaseCommandHandler<>).Assembly);
container.RegisterDecorator(typeof(ICommandHandler<>),
typeof(LoggerCommandHandlerDecorator<Command>));
container.RegisterDecorator(typeof(ICommandHandler<>),
typeof(ValidationCommandHandlerDecorator<Command>));
注意:ICommandHandler和BaseCommandHandler都駐留在不同的庫程序集中。這是有目的地完成的。
任何幫助將不勝感激!
曾爲喜歡一個魅力!感謝您的詳細解答。 – Ali