【发布时间】:2015-07-19 14:53:36
【问题描述】:
我要做的是使用以下代码将装饰器包裹在命令周围。
public interface ICommand
{
}
public interface ICommand<T> : ICommand where T : class
{
void Execute(T args);
}
public class TransactionalCommand<T> : ICommand<T>
where T : class
{
private readonly ICommand<T> command;
public TransactionalCommand(ICommand<T> command)
{
this.command = command;
}
public void Execute(T args)
{
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
this.command.Execute(args);
scope.Complete();
}
}
}
这是我调用解析的方式,但我只取回没有修饰的 ChangePasswordCommand。 (实际上它不会在第二个 Bind 上编译事件)
最终目标是使用这个装饰器自动注册我的所有类型。任何帮助都会很棒!
Bind<ChangePasswordCommand>().To<ChangePasswordCommand>()
.WhenInjectedInto<TransactionalCommand<ChangePasswordArgs>>();
Bind<ChangePasswordCommand>().To<TransactionalCommand<ChangePasswordArgs>>()
.InTransientScope();
var command = kernel.Get<ChangePasswordCommand>();
【问题讨论】:
标签: ninject ninject-2 ninject.web.mvc