ScopedUnitOfWork icon indicating copy to clipboard operation
ScopedUnitOfWork copied to clipboard

Not working with async/await

Open fubar-coder opened this issue 4 years ago • 0 comments

The _scopeStack of UnitOfWorkScopeManagerBase<TContext> has a ThreadStatic attribute, which doesn't work together with async/await. The solution is to use AsyncLocal instead.

Please take a look at this example for more information:

https://gist.github.com/JoshKeegan/66d649f6c5cc127d2f4057133d7d5bdc

You also link to the following article, which contains this warning:

Async Warning

Updated 2018-04-20 The code here was written before async use was wide spread and doesn’t work with async. The code relies on thread static variables, which will fail when a request is processed asynchronously, being handled by different threads.

fubar-coder avatar Oct 28 '21 21:10 fubar-coder