circles-arrows / blueprint41

An Object Graph Mapper for CSharp to connect to Neo4j or Memgraph.
http://www.blueprint41.com/
MIT License
31 stars 8 forks source link

Is Blueprint 41 Thread safe ready to be used for web api? #78

Open abhay-naik opened 2 months ago

abhay-naik commented 2 months ago

I am planning to use your library and was checking your code. I am trying to use in web api environment , how do you make your transaction thread safe with shared static Transaction class? Please do let me know so that I can use your library without any worry

circles-arrows commented 1 month ago

Internally the framework uses AsyncLocal and ThreadStatic to make a transaction scope that is valid within the scope of the using and methods called from within the using scope (so the entire call-stack below).

You can also see this issue that discusses how "Transactions are passed down the call tree."

Be aware though that the Transaction scope works with "using" (it's an IDisposable) and not "await using" (it's not an IAsyncDisposable), so async/await code inside the transaction should be wrapped in a Task.Run(...)