質問

For a class with below construct, constructor injection works great but not property. What else do i need to add to the conventions to make Inject attribute work

public partial class Repo
{
     [Inject] 
     public ILogger Logger{get;set;}
}

Bindings in NInjectWebCommon.cs

private static void RegisterServices(IKernel kernel)
        {
            //Dispose all resource after the requests ends
            kernel.Bind(x => x.FromAssembliesMatching("*").SelectAllClasses().BindAllInterface().Configure(scope=>scope.InRequestScope()));

        }
役に立ちましたか?

解決

I'm asuming that the repository class is instantiated by entity framework somehow. So if you are not requesting the repo isntance with ninject you need to build up the existing instance with ninject. That can be done with the Inject method on the kernel.

var kernel = new StandardKernel();
var repo = new Repo();
kernel.Inject(repo);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top