This is a small question, just to make sure I understand Unity correctly.
I use Unity in an ASP.NET MVC application and I registered the following type:
container.RegisterType<IPizzaService, PizzaService>();
And I use it in the controller, for example:
public class PizzaController : Controller { private IPizzaService _pizzaService; public PizzaController(IPizzaService pizzaService) { _pizzaService = pizzaService; } [HttpGet] public ActionResult Index() { var pizzasModel = _pizzaService.FindAllPizzas(); ... } }
Each time a page request is executed, a new instance of IPizzaService is introduced and used. So it all works great.
My question is: do I have to do anything special to destroy this instance? I assume that after the request is complete, the controller will be deleted and the PizzaService instance will eventually receive garbage collection.
If I need deterministic deletion of an instance because it uses the context of the entity framework or an unmanaged resource, for example, I need to override the Dispose of the controller, and make sure that I invoke the instance utility myself.
Right? If not, explain why :)
Thanks!
source share