开发者

Windsor PerWebRequest resolution in Application_Start

开发者 https://www.devze.com 2023-01-03 07:45 出处:网络
I am injecting HttpContextBase into a caching class. HttpContextBase is registered as PerWebRequest. I interact with the caching class on each web request and this works fine, but I also need to initi

I am injecting HttpContextBase into a caching class. HttpContextBase is registered as PerWebRequest. I interact with the caching class on each web request and this works fine, but I also need to initialise the cache at application start.

I unders开发者_运维技巧tand that PerWebRequest does not work in Application_Start though:

castle PerRequestLifestyle not recognize

What is the best way to resolve this in my situation?


Not use stuff that depends on per-web-request stuff outside of web request.

If you need to depend on a class you registered as PWR I'd suggest getting another component for that service with different lifestyle and using it in Application_Start and using IHandlerSelector to return PWR one when you're within a web request, and the other one otherwise


Try using an hybrid webrequest/transient lifestyle.


To warmup caches when the container starts I usually use the Startable Facility. Here is an example on how to use it: http://blog.bittercoder.com/PermaLink,guid,a621ddda-acb5-4afd-84ff-faafb96a2fa1.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消