【发布时间】:2012-07-19 09:31:19
【问题描述】:
我的简单示例有一个小问题。
我有简单的工厂接口:
public interface ICameraFactory
{
ICameraController GetNikonCamera();
ICameraController GetCanonCamera();
}
我将它绑定为工厂:
IKernel kernel = new StandardKernel();
kernel.Bind<ICameraFactory>().ToFactory();
当我尝试转换时:
kernel.Bind<ICameraController>().To<NikonCameraController>()
.Named("NikonCamera");
到:
kernel.Bind<ICameraController>().To<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
Ninject.Extension.Factory 3.0.1.0
编译错误:https://dl.dropbox.com/u/21806986/Screenshots/shot_19072012_133454.png
【问题讨论】:
标签: dependency-injection ninject ninject-extensions