I have a WEB API application and I am using UnityContainer as my DI. Since I'm using UnitOfWork with Entity Framework I wanted to register the DataContext in the UnityContainer per each request. I was disappointed to find that no LifeTimeManager exists that can give me a new scope per request. After digging a little more, I found that Unity.AspNet.Mvc does contain a PerRequestLifetimeManager. My questions are:
- Is there a reason why Unity doesn't contain a PerRequestLifetimeManager? It seems to me that is a very common case to register something per request.
- Is there a particular reason why Unity.AspNet.Mvc does contain PerRequestLifetimeManager?
- Is there something I need to know if I am using Unity.AspNet.Mvc in a WebApi project?
- In case of using Thread or Tasks, how does the container knows it belongs to the same request?