示例#1
0
        public void ConcurrentMessageContextsResultsInDifferentServices()
        {
            ScopedService service1 = null;
            ScopedService service2 = null;

            new Thread(() =>
            {
                using (TransactionContext.None())
                    using (MessageContext.Establish())
                    {
                        Thread.Sleep(200);
                        service1 = kernel.Get <ScopedService>();
                        while (service2 == null)
                        {
                        }
                    }
            }).Start();

            using (TransactionContext.None())
                using (MessageContext.Establish())
                {
                    Thread.Sleep(200);
                    service2 = kernel.Get <ScopedService>();
                    while (service1 == null)
                    {
                    }
                }

            service1.ShouldNotBe(service2);
        }
        public void ConcurrentMessageContextsResultsInDifferentServices()
        {
            ScopedService service1 = null;
            ScopedService service2 = null;

            new Thread(() =>
            {
                using (MessageContext.Establish(new Dictionary <string, object>()))
                {
                    Thread.Sleep(200);
                    service1 = container.Resolve <ScopedService>();
                    while (service2 == null)
                    {
                    }
                }
            }).Start();

            using (MessageContext.Establish(new Dictionary <string, object>()))
            {
                Thread.Sleep(200);
                service2 = container.Resolve <ScopedService>();
                while (service1 == null)
                {
                }
            }

            service1.ShouldNotBe(service2);
        }