PerRequestLifetimeManager can only be used in the context of an HTTP request

后端 未结 2 1386
既然无缘
既然无缘 2021-01-17 21:31

I have a MVC application that uses Unity as its IoC container and have multiple services defined in my application using the PerRequestLifetimeManager.

2条回答
  •  醉话见心
    2021-01-17 22:08

    I would suggest you to have 2 separate containers, with different configuration, for the web environment and for the background environment. So, for your web environment, you can control the lifetime per request and in a background task you can do it per thread.

    As you are using service locator, you could have 2 locators, like WebServiceLocator.Resolve<> and BackgroundServiceLocator.Resolve<>

提交回复
热议问题