Seeking One-Size-Fits-All Context Based Storage
First off, I wish context based storage was consistent across the framework!

With that said, I'm looking for an elegant solution to make these properties safe across ASP.NET, WCF and any other multithreaded .NET code. The properties are located in some low-level tracing helpers (these are exposed via methods if you're wondering why they're internal).

I'd rather not have a dependency on unneeded assemblies (like System.Web, etc). I don't want to require anyone using this code to configure anything. I just want it to work ;) That may be too tall of an order though...

Anyone have any tricks up there sleeves? (I've seen Spring's implementation)

        internal static string CurrentInstance
        {
            get
            {
                return CallContext.LogicalGetData(currentInstanceSlotName) as string;
            }
            set
            {
                CallContext.LogicalSetData(currentInstanceSlotName, value);
            }
        }

        internal static Stack<ActivityState> AmbientActivityId
        {
            get
            {
                Stack<ActivityState> stack = CallContext.LogicalGetData(ambientActivityStateSlotName) as Stack<ActivityState>;
                if (stack == null)
                {
                    stack = new Stack<ActivityState>();
                    CallContext.LogicalSetData(ambientActivityStateSlotName, stack);
                }

                return stack;
            }
        }
Seeking One-Size-Fits-All Context Based Storage
===

First off, I wish context based storage was consistent across the framework!

With that said, I'm looking for an elegant solution to make these properties safe across ASP.NET, WCF and any other multithreaded .NET code. The properties are located in some low-level tracing helpers (these are exposed via methods if you're wondering why they're internal).

I'd rather not have a dependency on unneeded assemblies (like System.Web, etc). I don't want to require anyone using this code to configure anything. I just want it to work ;) That may be too tall of an order though...

Anyone have any tricks up there sleeves? (I've seen Spring's implementation)

        internal static string CurrentInstance
        {
            get
            {
                return CallContext.LogicalGetData(currentInstanceSlotName) as string;
            }
            set
            {
                CallContext.LogicalSetData(currentInstanceSlotName, value);
            }
        }

        internal static Stack<ActivityState> AmbientActivityId
        {
            get
            {
                Stack<ActivityState> stack = CallContext.LogicalGetData(ambientActivityStateSlotName) as Stack<ActivityState>;
                if (stack == null)
                {
                    stack = new Stack<ActivityState>();
                    CallContext.LogicalSetData(ambientActivityStateSlotName, stack);
                }

                return stack;
            }
        }