Commit effbc21
Changed files (3)
product
Gorilla.Commons.Infrastructure
Transactions
product/Gorilla.Commons.Infrastructure/Transactions/IThread.cs
@@ -2,6 +2,6 @@ namespace Gorilla.Commons.Infrastructure.Transactions
{
public interface IThread
{
- T provide_slot_for<T>() where T : new();
+ T provide_slot_for<T>() where T : class, new();
}
}
\ No newline at end of file
product/Gorilla.Commons.Infrastructure/Transactions/Thread.cs
@@ -1,36 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class Thread : IThread
- {
- readonly object mutex = new object();
- readonly IDictionary<int, LocalDataStoreSlot> slots;
-
- public Thread()
- {
- slots = new Dictionary<int, LocalDataStoreSlot>();
- }
-
- public T provide_slot_for<T>() where T : new()
- {
- var id = System.Threading.Thread.CurrentThread.ManagedThreadId;
- within_lock(() =>
- {
- if (!slots.ContainsKey(id))
- {
- var slot = System.Threading.Thread.GetNamedDataSlot(GetType().FullName);
- slots.Add(id, slot);
- System.Threading.Thread.SetData(slot, new T());
- }
- });
- return (T) System.Threading.Thread.GetData(slots[id]);
- }
-
- void within_lock(Action action)
- {
- lock (mutex) action();
- }
- }
-}
\ No newline at end of file
product/Gorilla.Commons.Infrastructure/Gorilla.Commons.Infrastructure.csproj
@@ -132,7 +132,7 @@
<Compile Include="Transactions\Context.cs" />
<Compile Include="Transactions\ContextFactory.cs" />
<Compile Include="Transactions\ContextFactorySpecs.cs" />
- <Compile Include="Transactions\Thread.cs" />
+ <Compile Include="Transactions\CurrentThread.cs" />
<Compile Include="Transactions\EmptyUnitOfWork.cs" />
<Compile Include="Transactions\IChangeTracker.cs" />
<Compile Include="Transactions\IChangeTrackerFactory.cs" />