Ninject 2:是否有相当于 1.5 的 InjectPropertiesWhere 的工具?
我在我的 MVC 项目中使用 Ninject 1.5。它工作得很好,但由于我们有 Ninject 2,我可以升级(并且另外使用每个请求行为,这在 1.5 中无法正常工作)。 Ninject 1.5 有 InjectPropertiesWhere
函数,而 Ninject 2 中缺少该函数(至少我前段时间测试时是这样)。有类似的东西吗?
InjectPropertiesWhere
示例:
return Bind<IUserService>().To<UserService>()
.InjectPropertiesWhere(p => p.Name.EndsWith("Repository"))
.InjectPropertiesWhere(p => p.Name.EndsWith("Service"))
.InjectPropertiesWhere(p => p.Name == "ApplicationCache")
.InjectPropertiesWhere(p => p.Name == "CurrentPrincipal")
.InjectPropertiesWhere(p => p.Name == "CTEmailSender")
.InjectPropertiesWhere(p => p.Name == "CTSettings");
I am using Ninject 1.5 in my MVC project. It works nicely, but since we have Ninject 2, I could upgrade (and additionaly use per request behavior, which didn't work properly in 1.5). Ninject 1.5 had InjectPropertiesWhere
function, which is missing in Ninject 2 (at least it was when I tested it some time ago). Is there something similar?
Example of InjectPropertiesWhere
:
return Bind<IUserService>().To<UserService>()
.InjectPropertiesWhere(p => p.Name.EndsWith("Repository"))
.InjectPropertiesWhere(p => p.Name.EndsWith("Service"))
.InjectPropertiesWhere(p => p.Name == "ApplicationCache")
.InjectPropertiesWhere(p => p.Name == "CurrentPrincipal")
.InjectPropertiesWhere(p => p.Name == "CTEmailSender")
.InjectPropertiesWhere(p => p.Name == "CTSettings");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Ninject 2 不支持这种方式。您有 4 个选项:
WithProperty("propertyName", ctx => ctx.Kernel.Get())
This is not supported this way by Ninject 2. You have 4 Options:
WithProperty("propertyName", ctx => ctx.Kernel.Get<MyType>())