开发者

Unity+ Caching: how to keep an object instance that should be a singletone

开发者 https://www.devze.com 2023-01-26 22:26 出处:网络
I need my UnityContainer to contain an instance of CacheManager that should be created once and re-used for all future instances of containers.

I need my UnityContainer to contain an instance of CacheManager that should be created once and re-used for all future instances of containers.

I am creating new UnityContainer instance each time when I need it ('CreateChildContainer' is not used).

I开发者_C百科've created static member that contains my cache manager and registered it's instance.

Looking on this after half-year, I don't like static members...

Will it work if I will create a single instance of UnityContainer and register there the instance of CacheManager with 'ContainerControlledLifetimeManager' option?

Do you see any better way?

Thanks.


Keep an instance of the container around and use ContainerControlledLifetimeManager. Creating lots of containers is going to perform poorly.

0

精彩评论

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

关注公众号