NamedLikeFactoryMethod在Ninject扩展工厂工作不符合文档 [英] NamedLikeFactoryMethod in Ninject Extensions Factory working in non-compliance with documentation
本文介绍了NamedLikeFactoryMethod在Ninject扩展工厂工作不符合文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的工厂界面:
public interface ICameraFactory
{
ICameraController GetNikonCamera();
ICameraController GetCanonCamera();
}
我将其绑定为工厂:
IKernel kernel = new StandardKernel();
kernel.Bind< ICameraFactory>()。ToFactory();
当我尝试转换:
kernel.Bind< ICameraController>()。< NikonCameraController>()
.Named(NikonCamera);
to:
code> kernel.Bind< ICameraController>()。< NikonCameraController>()
.NamedLikeFactoryMethod< ICameraFactory>(f => f.GetNikonCamera());
它不编译。
例如,这段代码是被编译的(但是很糟糕):
kernel.Bind< ICameraController>()
。 ToMethod< ICameraController>(c => new NikonCameraController())
.NamedLikeFactoryMethod< ICameraController,ICameraFactory>(f => f.GetNikonCamera());
我做错了什么?
Ninject 3.0.1.10
编译错误: https:// dl .dropbox.com / u / 21806986 / Screenshots / shot_19072012_133454.png
解决方案
您可以使用:
this.kernel.Bind< ICameraController>()
.To< NikonCameraController>()
.NamedLikeFactoryMethod(( ICAMeraFactory f)=> f.GetNikonCamera());
I have a small issue with my simple example.
I have simple factory interface:
public interface ICameraFactory
{
ICameraController GetNikonCamera();
ICameraController GetCanonCamera();
}
I bind it as a factory:
IKernel kernel = new StandardKernel();
kernel.Bind<ICameraFactory>().ToFactory();
When i try to convert:
kernel.Bind<ICameraController>().To<NikonCameraController>()
.Named("NikonCamera");
to:
kernel.Bind<ICameraController>().To<NikonCameraController>()
.NamedLikeFactoryMethod<ICameraFactory>(f => f.GetNikonCamera());
it's don't compile.
For example, this code is compiled (but it's terrible):
kernel.Bind<ICameraController>()
.ToMethod<ICameraController>(c=>new NikonCameraController())
.NamedLikeFactoryMethod<ICameraController, ICameraFactory>(f => f.GetNikonCamera());
What am I doing wrong?
Ninject 3.0.1.10
Ninject.Extension.Factory 3.0.1.0
Compile error: https://dl.dropbox.com/u/21806986/Screenshots/shot_19072012_133454.png
解决方案
You can use:
this.kernel.Bind<ICameraController>()
.To<NikonCameraController>()
.NamedLikeFactoryMethod((ICameraFactory f) => f.GetNikonCamera());
这篇关于NamedLikeFactoryMethod在Ninject扩展工厂工作不符合文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文