0

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()));

        }
Deeptechtons
  • 10,945
  • 27
  • 96
  • 178
  • Ninject is probably not able to create that logger. Have you tried it with some plain object? Are you using logging extension for Ninject? – mipe34 Jan 02 '13 at 21:06
  • @mipe34 ILogger is a Interface i had developed no logging extension. What do i do to Inject the Interface then? – Deeptechtons Jan 03 '13 at 04:34
  • That should work. Which component is requesting the repo? And why is it partial? – Daniel Marbach Jan 07 '13 at 20:21
  • @DanielMarbach thanks for replying. It's been long time & no answers. Partial is there because one part of the file is auto-generated by the EntityFramework Model Designer i need to access the `Logger` in the partial class – Deeptechtons Jan 09 '13 at 17:42

1 Answers1

0

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);
Daniel Marbach
  • 2,294
  • 12
  • 15