是StructureMap型材线程安全的? [英] Are StructureMap profiles thread safe?

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

问题描述

我在考虑使用StructureMap的配置文件,以促进基于经过验证的用户的类型,提供了行为的微小差别,我的web应用程序中。我的问题是,如果我做这样的事情

I was thinking of using StructureMap's profiles to facilitate offering up slight differences in behavior in my web app based on the authenticated user's type. My question is, if I do something like

ObjectFactory.Profile = Session["UserType"];

时,它会是线程安全的,或将有可能同时请求与对方解决基于配置文件的事情时,干扰?

is it going to be thread-safe or will simultaneous requests potentially interfere with each other when resolving things based on the profile?

推荐答案

在静态的ObjectFactory门面的操作都是线程安全的。这意味着你可以安全地调用它们在不同的线程,而不破坏的ObjectFactory的内部状态。

The operations on the static ObjectFactory facade are all "thread safe". This means that you can safely call them on different threads without corrupting the internal state of the ObjectFactory.

但是,你问的是每个线程是否得到的ObjectFactory其自己的个人副本,答案是否定的。你做出的ObjectFactory在任何线程的任何变化,都会反映在的AppDomain中的所有其他线程。

However, what you are asking is whether each thread gets its own personal copy of the ObjectFactory, and the answer is no. Any change you make to ObjectFactory on any thread, will be reflected in all other threads within the AppDomain.

该配置文件功能可能不是你正在寻找的解决方案。你可能想使用这样的命名实例:

The Profiles feature is probably not the solution you are looking for. You probably want to use something like named instances:

ObjectFactory.GetInstance<ISomeService>( Session["UserType"] );

有其他可能的解决方案,这取决于你正在努力做的事情。考虑发布一个关于你正在试图解决这个问题,前一个问题:我如何才能根据当前用户的用户类型不同的行为。

There are other potential solutions, depending on what you are trying to do. Consider posting a question about the problem you are trying to solve, ex: "how do I get different behavior based on the current user's UserType..."

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

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