Are StructureMap profiles thread safe?

点点圈 提交于 2019-12-11 07:54:01

问题


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?


回答1:


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.

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..."



来源:https://stackoverflow.com/questions/1494937/are-structuremap-profiles-thread-safe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!