private void ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadProcedure(object o)
        {
            ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadInformation info = o as ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadInformation;

            IHaveManyGenericTypesClosed resolve1 = info.Container.Resolve <IHaveManyGenericTypesClosed>();
            IHaveManyGenericTypesClosed resolve2 = info.Container.Resolve <IHaveManyGenericTypesClosed>();

            Assert.AreSame(resolve1, resolve2);

            info.SetThreadResult(Thread.CurrentThread, resolve1);
        }
        public void ContainerReturnsDifferentInstancesOnDifferentThreads()
        {
            IUnityContainer container = new UnityContainer();

            container.RegisterType <IHaveManyGenericTypesClosed, HaveManyGenericTypesClosed>(new PerThreadLifetimeManager());

            Thread t1 = new Thread(new ParameterizedThreadStart(ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadProcedure));
            Thread t2 = new Thread(new ParameterizedThreadStart(ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadProcedure));

            ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadInformation info =
                new ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadInformation(container);

            t1.Start(info);
            t2.Start(info);
            t1.Join();
            t2.Join();

            IHaveManyGenericTypesClosed a = new List <IHaveManyGenericTypesClosed>(info.ThreadResults.Values)[0];
            IHaveManyGenericTypesClosed b = new List <IHaveManyGenericTypesClosed>(info.ThreadResults.Values)[1];

            Assert.AreNotSame(a, b);
        }
        public void ContainerReturnsDifferentInstancesOnDifferentThreads()
        {
            IUnityContainer container = new UnityContainer();

            container.RegisterType<IHaveManyGenericTypesClosed, HaveManyGenericTypesClosed>(new PerThreadLifetimeManager());

            Thread t1 = new Thread(new ParameterizedThreadStart(ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadProcedure));
            Thread t2 = new Thread(new ParameterizedThreadStart(ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadProcedure));

            ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadInformation info =
                new ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadInformation(container);

            t1.Start(info);
            t2.Start(info);
            t1.Join();
            t2.Join();

            IHaveManyGenericTypesClosed a = new List<IHaveManyGenericTypesClosed>(info.ThreadResults.Values)[0];
            IHaveManyGenericTypesClosed b = new List<IHaveManyGenericTypesClosed>(info.ThreadResults.Values)[1];

            Assert.AreNotSame(a, b);
        }