是CreateChildContainer()线程安全的? [英] Is CreateChildContainer() Thread-Safe?

查看:298
本文介绍了是CreateChildContainer()线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早在2009年,这可能是pre-统一2.0,我看到一个讨论这表明CreateChildContainer(线程)不是线程安全的:

Back in 2009, which may have been pre-Unity 2.0, I see a thread of discussion which suggests CreateChildContainer() is not thread safe:

另外,如果你创建子容器CreateChildContainer()方法,它们将增加自理到其父容器的livetime容器创建过程中和处理时删除。所以,从单独的线程处理子容器可能会导致错误,甚至只有一个线程访问的每个子容器的时间。

Also, if you create child container with CreateChildContainer() method, they will add themself to its parent container’s livetime container during creation and remove when disposing. So, disposing child containers from separate threads may lead to errors, even each child container accessed only by one thread at time.

时,确实(仍然)适用于统一2.0?那么统一3.0或超出了?

Is that indeed (still) true for Unity 2.0? What about Unity 3.0 or beyond?

这是特别重要的,如果实现统一与WCF,如<一个描述href="http://www.devtrends.co.uk/blog/introducing-unity.wcf-providing-easy-ioc-integration-for-your-wcf-services"相对=nofollow>这篇文章。该想法是使用一个子容器容易地处置HierarchylifetimeManager实例。虽然我不知道现在如果不是PerRequestlifetimemanager应该没有孩子的容器都可以使用。

This is of particular interest if implementing Unity with WCF, as described in this article. The idea is to use a child-container to easily dispose of HierarchylifetimeManager instances. Though I'm wondering now if instead a PerRequestlifetimemanager should be used with no child-containers at all.

推荐答案

根据最新的源$ C ​​$ C(统一3.5)。它应该是线程安全的。它增加了其自于母公司的一生室内用的容器 parent.lifetimeContainer.Add(本); annd的添加用途实施锁()围绕儿童的私人列表中modficiations。

Based on the latest source code (Unity 3.5). It should be thread safe. It adds its self to parent's lifetime container wiht parent.lifetimeContainer.Add(this); annd the implementation of Add uses lock() around the modficiations of its private list of children.

这篇关于是CreateChildContainer()线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆