I am using ASP.NET MVC 4 with SimpleInjector and came across an issue when the MVC framework is trying to resolve the concrete type it should create when passing the object back to the controller action from the view. This is the only place it does not work, I get an error [MissingMethodException: Cannot create an instance of an interface.]
I know there have been similar questions asked, but none that really deal with this exactly. Is the best practice to write a custom ModelBinder? or am I missing something with SimpleInjector? It seems curious to me that this does not work when everything else (like constructor injection) works pretty well.
View:
@model IEntityType
... Rest of View
Controller:
public ActionResult Update(IEntityType entityType)
{
... controller code
return RedirectToAction("Index");
}
Global.asax
Container container = new SimpleInjector.Container();
container.Register<IEntityType, EntityTypeModel>();
IEntityType Definition:
public interface IEntityType
{
Int32 EntityTypeId { get; set; }
Guid EntityTypeGUID { get; set; }
String EntityTypeName { get; set; }
String EntityTypeDescription { get; set; }
}
EntityTypeModel Definition:
public class EntityTypeModel : IEntityType
{
public Int32 EntityTypeId { get; set; }
public Guid EntityTypeGUID { get; set; }
public String EntityTypeName { get; set; }
public String EntityTypeDescription { get; set; }
}