summaryrefslogtreecommitdiff
path: root/product/database/transactions/CurrentThread.cs
diff options
context:
space:
mode:
Diffstat (limited to 'product/database/transactions/CurrentThread.cs')
-rw-r--r--product/database/transactions/CurrentThread.cs19
1 files changed, 19 insertions, 0 deletions
diff --git a/product/database/transactions/CurrentThread.cs b/product/database/transactions/CurrentThread.cs
new file mode 100644
index 0000000..00be2fa
--- /dev/null
+++ b/product/database/transactions/CurrentThread.cs
@@ -0,0 +1,19 @@
+using System.Threading;
+
+namespace momoney.database.transactions
+{
+ public class CurrentThread : IThread
+ {
+ public T provide_slot_for<T>() where T : class, new()
+ {
+ var slot = Thread.GetNamedDataSlot(create_key_for<T>());
+ if (null == Thread.GetData(slot)) Thread.SetData(slot, new T());
+ return (T) Thread.GetData(slot);
+ }
+
+ string create_key_for<T>()
+ {
+ return Thread.CurrentThread.ManagedThreadId + GetType().FullName + typeof (T).FullName;
+ }
+ }
+} \ No newline at end of file