Added DictionaryAdapter.build.
[castle.git] / Services / Transaction / Castle.Services.Transaction / TLSActivityManager.cs
blob9450c77eb3d73e5149b70e504977d5a36a02a486
1 namespace Castle.Services.Transaction
3 using System;
4 using System.Threading;
6 public class TLSActivityManager : MarshalByRefObject, IActivityManager
8 private const string Key = "Castle.Services.Transaction.TLSActivity";
10 private object lockObj = new object();
11 private static LocalDataStoreSlot dataSlot;
13 static TLSActivityManager()
15 dataSlot = Thread.AllocateNamedDataSlot(Key);
18 #region MarshalByRefObject
20 ///<summary>
21 ///Obtains a lifetime service object to control the lifetime policy for this instance.
22 ///</summary>
23 ///
24 ///<returns>
25 ///An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease"></see> used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the <see cref="P:System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseManagerPollTime"></see> property.
26 ///</returns>
27 ///
28 ///<exception cref="T:System.Security.SecurityException">The immediate caller does not have infrastructure permission. </exception><filterpriority>2</filterpriority><PermissionSet><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="RemotingConfiguration, Infrastructure" /></PermissionSet>
29 public override object InitializeLifetimeService()
31 return null;
34 #endregion
36 /// <summary>
37 /// Gets the current activity.
38 /// </summary>
39 /// <value>The current activity.</value>
40 public Activity CurrentActivity
42 get
44 lock (lockObj)
46 Activity activity = (Activity) Thread.GetData(dataSlot);
48 if (activity == null)
50 activity = new Activity();
51 Thread.SetData(dataSlot, activity);
54 return activity;