15.11.08

IoC in ASP.NET MVC

We used the repository pattern(DomainDrivenDesign) to implement an injectable repository type in the peristence controllers in our ASP.NET MVC application.



HandleError(View = "AddItemError",ExceptionType=typeof(CreateItemException))]
public class PersistenceController:Controller
{
private readonly IPersistenceManager _persistenceManager;

public PersistenceController(IPersistenceManager persistenceManager)
{
_persistenceManager = persistenceManager;
}

public PersistenceController():this(PersistenceFactory.CreateInstance())
{
}


The PersistenceFactory was introduced to decouple the concrete types created from the actual client using the type.

No comments: