3

I am using property injection in my custom role provider like so:

public class MyRoleProvider : RoleProvider
{
    [Inject]
    public IRoleRepository RoleRepository { get; set; }
    ...
}

My ninject module:

public class MyNinjectModule : NinjectModule
{
    public override void Load()
    {
        Bind<IRoleRepository>().To<RoleRepository>();
    }
}

But when I try to use the RoleRepository property from within MyRoleProvider it is always null. Why isn't ninject injecting a RoleRepository instance into the property?

Bob
  • 821
  • 1
  • 17
  • 36

1 Answers1

0

Try doing constructor injection and see if you have the same problem. Sometimes the property injection doesn't happen in time to use the injected object.

public class MyRoleProvider:RoleProvider
{
    public MyRoleProvider(IRoleRepository repository)
    {
        //set class level var or property to repository
    }
    ...
}
JayGlynn
  • 77
  • 1
  • 6