質問

I use Nineject for .NET ioc container. I would like to use the factory method, but I can not. There is not .ToFactory method.

I added to project the Ninject.Extensions.Factory extension for Ninejct for .NET 3.0.1.10 and I added the CastleCore 3.0 to the project then I would like to invoke the ToFactory method, I do not see it.

There are, ToMethod, ToProvider method, but there is not ToFactory

I tried on this code:

public class Foo
{
    private IBarFactroy barFactroy;
    public Foo(IBarFactory barFactory)
    {
        this.barFactory = barFactory;
    }

    public void Do()
    {
        var bar = this.barFactroy.CreateBar();
    }
}

public interface IBarFactory
{
    Bar CreateBar();
}

in this way

kernel.Bind<IBarFactory>().ToFactory();

Why am I not able to invoke the ToFactory method?

I see the NuGet installed the ninject 3.0.2 prelease ninject for .net

役に立ちましたか?

解決

You need to add a namespace reference:

using Ninject.Extensions.Factory;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top