Ninject conditional binding

廉价感情. 提交于 2019-12-05 12:45:52

The ctx parameter is just one input into the contextual binding - there's nothing saying you need to pay the slightest bit of attention to it (except you need to be signature compatible with the delegate signature).

Bear in mind the RRR pattern though and don't go crazy.

IOW you need to be (in V2 syntax doing it):

Bind<IWarrior>().To<Samurai>().When(_ => expression not involving context at all);

(Where _ is a poor man's pidgin use of the F# pattern matching syntax for ignoring inputs)

In this special case I wouldn't replace the logger instance but rather configure your logging framework to log exactly what you want to.

Also the When condition does not depend on the target you can put there any kind of condition. E.g.

When(ctx => Configuration.Get("VerborsityLevel") == "quiet")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!