与 Ninject 2.0 的上下文绑定
在 Ninject 1.0 中,我有以下绑定定义:
Bind<ITarget>().To<Target1>().Only(When.Context.Variable("variable").EqualTo(true));
Bind<ITarget>().To<Target2>();
给定这样的绑定,我进行了调用:
ITarget target = kernel.Get<ITarget>(With.Parameters.ContextVariable("variable", true));
ITarget target = kernel.Get<ITarget>(With.Parameters.ContextVariable("variable", false));
第一个调用被解析为 Target1 的实例,第二个调用被解析为 Target2 的实例。
如何将其转化为 Ninject 2.0?
In Ninject 1.0 I had following binding definitions:
Bind<ITarget>().To<Target1>().Only(When.Context.Variable("variable").EqualTo(true));
Bind<ITarget>().To<Target2>();
Given such bindings I had calls:
ITarget target = kernel.Get<ITarget>(With.Parameters.ContextVariable("variable", true));
ITarget target = kernel.Get<ITarget>(With.Parameters.ContextVariable("variable", false));
First call was resolved to instance of Target1, second call was resolved to instance of Target2.
How to translate this into Ninject 2.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用元数据,
You can use metadata,