I am currently working on an MVC 3 project, using Ninject as my DI, business objects are stored in a separate assembly. I encountered a problem with the controller parameters, when I send it back to CRUD operations, I get the error message "Unable to instantiate interface". I know that you cannot create an instance of the interface, but it seems to me that the only way around this is to use a custom mediator and pass in the FormCollection. This seems really messy, and I want to save as much type of specific code from the project as possible, so it's everywhere and Ninject for DI concrete. Not only does custom model binding seem messy - will I not lose my DataAnnotations?
Some code to describe what I have:
public ActionResult Create()
{
var objectToCreate = new ConcereteType();
return (objectToEdit);
}
[HttpPost]
public ActionResult Create(IRecord record)
{
if (ModelState.IsValue)
{
_repository.Create(record);
return View();
}
return View(record);
}
Has anyone come across this before? How did you overcome it?
Thank!
source
share