I have MVC webApi application which works with Unity. I have to resolve interface ITest to singleton class (DelegateHandler). But interface ITest has per httprequest lifetime manager and it is important. So i can’t resolve ITest on Application_Start event because there isn’t HttpRequest right now but DelegateHandler will use ITest only in httprequest life cycle.
So is it possible to send lazy resolve to DelegateHandler or maybe somebody have other interesting solution?
The lifetime of a service should always be equal or shorter than that of its dependencies, so you would typically register
ITestas Per Http Request or Transient, but if that’s not possible, wrap the dependency (DelegateHandlerI assume) that has a per Http Request lifetime in a proxy: