Ninject 2: Is there an equivalent of 1.5 InjectPropertiesWhere?

I am using Ninject 1.5 in my MVC project. It works well, but since we have Ninject 2, I could update (and additionally use behavior for each request that does not work properly in 1.5). Ninject 1.5 had a feature InjectPropertiesWherethat was missing in Ninject 2 (at least that was when I checked it a while ago). Is there something similar?

An example 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");
+3
source share
1 answer

It is not supported in this way of Ninject 2. You have 4 options:

  • Switch to constructor injection, which is always the preferred injection method.
  • Inject ( add)
  • WithProperty("propertyName", ctx => ctx.Kernel.Get<MyType>())
  • , , . , , ​​ .
+6

Source: https://habr.com/ru/post/1792126/


All Articles