I'm using Unity Application Block together with UnityMvc. I have a controller named HomeController that has an action:
public ActionResult Add(UnitOfWork UnitOfWork)
{
Person p = new Person();
p.Code = "1202";
p.City = new City() { Code = "21", Name = "Paris" };
UnitOfWork.Save();
ViewBag.Message = "Done.";
return View();
}
UnitOfWork parameter has a constructor like this:
public UnitOfWork(Context Context)
{
this.context = Context;
}
and a "Save" Method:
public void Save()
{
this.context.SaveChanges();
}
When unity tries to construct UnitOfWork Object for "Add" action it produces the following error:
No parameterless constructor defined for this object.
It seems as UnitOfWork is a parameter itself for "Add" action, it should have a parameterless constructor.
Is it true or any body has a solution?