internal static IStardustContext CreateScope()
        {
            var id  = Guid.NewGuid();
            var ctx = ThreadSynchronizationContext.BeginContext(id);

            lock (StateStorage)
            {
                if (!StateStorage.TryAdd(id.ToString(), new StardustContextProvider()))
                {
                    Logging.DebugMessage("Unable to initialize context");
                }
                if (DoLogging)
                {
                    Logging.DebugMessage("creating scope storage for {0}", id);
                }
            }
            ContainerFactory.Current.Bind(typeof(Guid?), id, Scope.Context);
            var runtime = RuntimeFactory.CreateRuntime(Scope.PerRequest);

            ContainerFactory.Current.Bind(typeof(IRuntime), runtime, Scope.Context);
            ContainerFactory.Current.Bind(runtime.GetType(), runtime, Scope.Context);
            ContainerFactory.Current.Bind(typeof(InvokationMarker), new InvokationMarker(DateTime.UtcNow), Scope.Context);
            ContainerFactory.Current.Bind(typeof(TraceHandler), new TraceHandler(), Scope.Context);
            ctx.SetDisconnectorAction(CurrentContextOnOperationCompleted);
            return(ctx);
        }
Exemple #2
0
        internal static IStardustContext CreateScope()
        {
            var id  = Guid.NewGuid();
            var ctx = ThreadSynchronizationContext.BeginContext(id);


            ContainerFactory.Current.Bind(typeof(Guid?), id, Scope.Context);
            var runtime = RuntimeFactory.CreateRuntime(Scope.PerRequest);

            ContainerFactory.Current.Bind(typeof(IRuntime), runtime, Scope.Context);
            ContainerFactory.Current.Bind(typeof(InvokationMarker), new InvokationMarker(DateTime.UtcNow), Scope.Context);
            ContainerFactory.Current.Bind(typeof(TraceHandler), new TraceHandler(), Scope.Context);
            ctx.Disposing += CurrentContextOnOperationCompleted;
            return(ctx);
        }
 private static StardustContextProvider GetStardustContextProvider(IStardustContext currentContext)
 {
     try
     {
         if (currentContext == null)
         {
             Logging.DebugMessage("WTF??");
             currentContext = ThreadSynchronizationContext.BeginContext(Guid.NewGuid());
         }
         return(((ThreadSynchronizationContext)currentContext).StateContainer);
     }
     catch (Exception ex)
     {
         Logging.Exception(ex);
         throw;
     }
 }
Exemple #4
0
        public async Task CustomScopeContextHandler()
        {
            second = Guid.NewGuid();
            try
            {
                Guid main;
                using (var maincs = ThreadSynchronizationContext.BeginContext() as ThreadSynchronizationContext)
                {
                    Console.WriteLine("managed thread id {0}", Thread.CurrentThread.ManagedThreadId);
                    Console.WriteLine(maincs.Id.ToString());
                    main = maincs.Id;
                    var myvalue = await CreateTestTask();

                    Console.WriteLine("managed thread id {0}", Thread.CurrentThread.ManagedThreadId);
                    Console.WriteLine(maincs.Id.ToString());
                    Assert.AreEqual("myNewItem", myvalue);
                }
                Assert.AreEqual(main, second);
            }
            catch (Exception ex)
            {
                Assert.Fail();
            }
        }