Question

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

Was it helpful?

Solution

You can use:

this.kernel.Bind<ICameraController>()
           .To<NikonCameraController>()
           .NamedLikeFactoryMethod((ICameraFactory f) => f.GetNikonCamera());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top