基于 Ninject 约定的绑定
我再次认为我可能错过了这里显而易见的事情。我希望按照约定进行自动绑定。我一直在研究 Ninject.extension.conventions 项目和程序集扫描器。
我有很多看起来像下面这样的行,我想自动绑定:
Bind<ICommandHandler<MyCommand>>().To<MyCommandHandler>();
Bind<ICommandHandler<MyOtherCommand>>().To<MyOtherCommandHander>();
我已经尝试了几种变体:
Kernal.Scan(x => {
x.FromAssemblyContaining<MyCommand>();
x.WhereTypeInheritsFrom(typeof(ICommandHander<>));
x.BindWith(new DefaultBindingGenerator());
});
但是在以下情况下没有返回实例:
kernel.Get<ICommandHandler<T>>();
Once again I think I might be missing the obvious here. I'm looking to do auto binding by conventions. I've been looking at the Ninject.extension.conventions project and the assembly scanner.
What I have is a lot lines that look like the following, that I would like to auto bind:
Bind<ICommandHandler<MyCommand>>().To<MyCommandHandler>();
Bind<ICommandHandler<MyOtherCommand>>().To<MyOtherCommandHander>();
I've tried several variations of:
Kernal.Scan(x => {
x.FromAssemblyContaining<MyCommand>();
x.WhereTypeInheritsFrom(typeof(ICommandHander<>));
x.BindWith(new DefaultBindingGenerator());
});
But there are no instances returned when:
kernel.Get<ICommandHandler<T>>();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试查看 GenericBindingGenerator 而不是 DefaultBindingGenerator。
try looking at
GenericBindingGenerator
instead ofDefaultBindingGenerator
.解决办法:
The solution: