Here is my BaseController
:
using Ferrero.Data;
using System;
using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.Mvc;
namespace Ferrero.Web.Controllers
{
public abstract class BaseController : Controller
{
protected IFerreroUow Uow { get; set; }
public MasterLayoutView masterlayout = new MasterLayoutView();
}
}
And here is my HomeController
which inherits from BaseController
:
using Ferrero.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ferrero.Model;
namespace Ferrero.Web.Controllers
{
public class HomeController : BaseController
{
public HomeController(IFerreroUow uow)
{
Uow = uow;
}
public ActionResult Index()
{
ViewBag.Title = "Home Page";
masterlayout.employees_list = Uow.Employees.GetAll().ToList();
return View();
}
}
}
The Uow is a unit of work where I have all my Repositories and I want it to be available in every controller. The thing is that I am not using the Ioc correctly and I get this error when I run the application
An error occurred when trying to create a controller of type 'Ferrero.Web.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.
Can anyone help me please?