ninject继承的接口
|
我有以下两个基本接口,一个继承另一个。我将它们绑定到以下实现。
public interface IUnitOfWork { }
public interface IEventStoreUnitOfWork : IUnitOfWork { }
public class TransactionalHandler<TCommand, TCommandHandler> {
public TransactionalHandler(IUnitOfWork unitOfWork) {
// removed
}
}
public class EventStoreUnitOfWork : IEventStoreUnitOfWork { }
绑定...
Bind<IEventStoreUnitOfWork>().To<EventStoreUnitOfWork>();
Bind<TransactionalHandler<IDomainCommand, IDomainCommandHandler<IDomainCommand>>>()
.ToSelf()
.WithConstructorArgument(\"unitOfWork\", Kernel.GetService(typeof(IEventStoreUnitOfWork)));
这是行不通的。错误是:
Error activating IUnitOfWork
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency IUnitOfWork into parameter unitOfWork of constructor of type TransactionalHandler{CreateUserCmd, CreateUserCmdHandler}
1) Request for TransactionalHandler{CreateUserCmd, CreateUserCmdHandler}
这里发生了什么?显然,IUnitOfWork是由IEventStoreUnitOfWork继承的,并且具有绑定。我事件尝试了这个,但是我得到了同样的错误...
Bind<TransactionalHandler<IDomainCommand, IDomainCommandHandler<IDomainCommand>>>()
.ToSelf()
.WithConstructorArgument(\"unitOfWork\", Kernel.GetService(typeof(IEventStoreUnitOfWork)) as IUnitOfWork);
有任何想法吗?
谢谢
没有找到相关结果
已邀请:
2 个回复
筷啸够对铅
容淑阔九