示例#1
0
        public void SingletonCallSite_Test()
        {
            int x = 1;
            var callSite = new SingletonCallSite(() => lmps => x++);

            var t = new Thread(() =>
            {
                Assert.Equal(1, callSite.Invoke());
                Assert.Equal(1, callSite.Invoke());
            });
            t.Start();
            t.Join();
            var t2 = new Thread(() =>
            {
                Assert.Equal(1, callSite.Invoke());
                Assert.Equal(1, callSite.Invoke());
            });
            t2.Start();
            t2.Join();

            Assert.Equal(2, x);
            Assert.Equal(ServiceLifetime.Singleton, callSite.Lifetime);
        }