У меня есть два основных интерфейса, как показано ниже, один наследует другой. Я связываю их с реализациями, как показано ниже.
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);
Есть идеи?
Спасибо