Ninject: Abstract Class

Posted by Pickels on Stack Overflow See other posts from Stack Overflow or by Pickels
Published on 2010-05-14T08:21:31Z Indexed on 2010/05/14 8:24 UTC
Read the original article Hit count: 285

Filed under:
|
|
|

Hello,

Do I need to do something different in an abstract class to get dependency injection working with Ninject?

I have a base controller with the following code:

public abstract class BaseController : Controller
{
    public IAccountRepository AccountRepository
    {
        get;
        set;
    }
}

My module looks like this:

public class WebDependencyModule : NinjectModule
{
    public override void Load()
    {
        Bind<IAccountRepository>().To<AccountRepository>();
    }
}

And this is my Global.asax:

protected override void OnApplicationStarted()
{
    Kernel.Load(new WebDependencyModule());
}

protected override IKernel CreateKernel()
{
    return new StandardKernel();
}

It works when I decorate the IAccountRepository property with the [Inject] attribute.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about ninject

Related posts about ninject-2