C# MVC 5 Custom controller class to inherit from
<p>I have a repository that I want to use on all of my pages.</p>

<p>By default, all of MVC controllers inherit from <code>Controller</code> class. I have created <code>CustomBaseController</code> class where I have defined field for my <code>Repository</code> and I have instantiated repo with context in <code>CustomBaseController</code> constructor.</p>

<p>How ever, when I want to create a new controller e.g. <code>HomeController</code> that inherits from <code>CustomBaseController</code>, my repository field (db) is not visible.</p>

<p>Here is example from my new <code>CustomBaseController</code> :</p>

<pre><code>public class CustomBaseController : Controller {
    private IRepository db; // &lt;-- defined
    public CustomController() {
        // here it is initialized
        db = new DbRepository(new ApplicationDBContext());
    }
}
</code></pre>

<p>And also from my <code>HomeController</code> :</p>

<pre><code>public class ProgramController : CustomBaseController
{
    // GET: Program
    public ActionResult Index()
    {
        // db is not accessible here for some reason, 
        // like it wasn't inherited from CustomBaseController
        var user = db.getUserByID(1);
        return List(user);
    }
...
</code></pre>