コード例 #1
0
        public void Singleton_Implementation_Behavior()
        {
            var o0 = new TestService1();

            _c.Register(new ComponentDefinition <ITestService1, TestService1>(Lifestyle.Singleton, implementation: o0));
            var o1 = _c.Get <ITestService1>();
            var o2 = _c.Get <ITestService1>();

            Assert.NotNull(o1);
            Assert.AreSame(o1, o2);
            Assert.AreSame(o1, o0);
            _c.Release(o1);
            o2 = _c.Get <ITestService1>();
            Assert.AreSame(o2, o1);
        }
コード例 #2
0
        public void Extensions_Behavior()
        {
            var o1 = new TestService1();
            var o2 = new TestService1();

            _c.Register(new ComponentDefinition <ITestService1, TestService1>(Lifestyle.Extension));
            _c.Register(new ComponentDefinition <ITestService1, TestService1>(Lifestyle.Extension, implementation: o1));
            _c.Register(new ComponentDefinition <ITestService1, TestService1>(Lifestyle.Extension, implementation: o2));
            var ext1 = _c.All <ITestService1>().ToList();
            var ext2 = _c.All <ITestService1>().ToList();

            Assert.AreSame(ext1[1], o1);
            Assert.AreSame(ext1[2], o2);
            Assert.AreSame(ext2[1], o1);
            Assert.AreSame(ext2[2], o2);
            Assert.AreNotSame(ext1[0], ext2[0]);
        }