1

The current advice for using an Entity Manager in an ASP.NET request seems to be to just set the AuthorizedThreadID property to NULL (reference 1 and 2). While that works, it seems like that is turning off a very important 'safety net'. While I try very hard to use the Entity Manager in a thread-safe way, it is still nice to have that safety net in case I get it wrong...so I'd rather not have to just set it to NULL.

In the ASP.NET world, there is still roughly a single thread of execution - it's just that the actual thread can change when you are doing async work. I can think of a few possible solutions:

  1. The EntityManager.SafeThreadingCheck() method does some kind of extra magic to support ASP.NET requests. I can understand that IdeaBlade might not want to do this...which leads me to the second option...
  2. EntityManager provides some extensibility points for me to provide my own version of SafeThreadingCheck() where I can implement the special magic for verifying that the entity manager is still 'logically' on the request thread. I might have to do some weird stuff here but I don't think it would be terribly complicated.
  3. I try to use other extensibility points to detect when I should call my own FancySafeThreadingCheck() method. This has the downside that I have to try to hook into all the necessary places whereas the existing SafeThreadingCheck() method is already being called (presumably) from all the necessary places at exactly the best time.

I can understand this might not be the highest priority feature request but it also seems like it might not be too hard (at least for option #2). Or perhaps there are some other workarounds that may be better? My end goal is to avoid turning off this safety check...I'm open to options to get there.

4

1 回答 1

1

DevForce 7.2.4 将包含在 EntityManager 上设置委托以提供自定义授权线程 ID 逻辑的功能。

于 2014-07-02T21:41:54.517 回答