Injecting a dependancy into a base class
Posted
by Jamie Dixon
on Stack Overflow
See other posts from Stack Overflow
or by Jamie Dixon
Published on 2010-05-28T12:39:01Z
Indexed on
2010/05/28
12:41 UTC
Read the original article
Hit count: 227
Hey everyone,
I'm on a roll today with questions.
I'm starting out with Dependency Injection and am having some trouble injecting a dependency into a base class.
I have a BaseController
controller which my other controllers inherit from. Inside of this base controller I do a number of checks such as determining if the user has the right privileges to view the current page, checking for the existence of some session variables etc.
I have a dependency inside of this base controller that I'd like to inject using Ninject however when I set this up as I would for my other dependencies I'm told by the compiler that:
Error 1 'MyProject.Controllers.BaseController' does not contain a constructor that takes 0 argument
This makes sense but I'm just not sure how to inject this dependency. Should I be using this pattern of using a base controller at all or should I be doing this in a more efficient/correct way?
© Stack Overflow or respective owner