コード例 #1
0
        public void TestReleaseIDestructible()
        {
            SimpleIoc.Default.Reset();
            TestClassForIDestructible.Reset();
            TestClassForIDestructible releaseInstance = null;

            SimpleIoc.Default.RegisterWithLifetime <TestClassForIDestructible>(new TransitionLifetime())
            .OnDestroy((obj) => { releaseInstance = obj; });

            var inst1 = SimpleIoc.Default.GetInstance <TestClassForIDestructible>();

            Assert.AreEqual(1, SimpleIoc.Default.GetAllInstances(typeof(TestClassForIDestructible)).Count());
            inst1.Candidate.Release();
            Assert.AreEqual(0, SimpleIoc.Default.GetAllInstances(typeof(TestClassForIDestructible)).Count());
            Assert.AreEqual(inst1, releaseInstance);
        }
コード例 #2
0
        public void TestEventRegisterIDestructible()
        {
            SimpleIoc.Default.Reset();
            TestClassForIDestructible.Reset();
            TestClassForIDestructible releaseInstance = null;

            System.Windows.Window w = new System.Windows.Window();
            //SimpleIoc.Default.RegisterWithLifetime<TestClassForIDestructible>(new TransitionLifetime())
            // .DestroyOnEvent( (o) => w.Closed += o.DoRelease );

            var inst1 = SimpleIoc.Default.GetInstance <TestClassForIDestructible>();

            Assert.AreEqual(1, SimpleIoc.Default.GetAllInstances(typeof(TestClassForIDestructible)).Count());
            inst1.Candidate.Release();
            Assert.AreEqual(0, SimpleIoc.Default.GetAllInstances(typeof(TestClassForIDestructible)).Count());
            Assert.AreEqual(inst1, releaseInstance);
        }
コード例 #3
0
        public void TestCreationTimeForIDestructible()
        {
            SimpleIoc.Default.Reset();
            TestClassForIDestructible.Reset();
            Assert.AreEqual(0, TestClassForIDestructible.InstancesCreated);
            SimpleIoc.Default.RegisterWithLifetime <TestClassForIDestructible>(new TransitionLifetime());
            Assert.AreEqual(0, TestClassForIDestructible.InstancesCreated);

            var inst1 = SimpleIoc.Default.GetInstance <TestClassForIDestructible>();

            Assert.AreEqual(1, TestClassForIDestructible.InstancesCreated);
            Assert.IsNotNull(inst1);
            Assert.IsNotNull(inst1.Candidate);
            Assert.IsInstanceOfType <TransitionLifetime>(inst1.Candidate);
            Assert.AreEqual(1, SimpleIoc.Default.GetAllInstances(typeof(TestClassForIDestructible)).Count());

            inst1.Candidate.Release();
            Assert.AreEqual(0, SimpleIoc.Default.GetAllInstances(typeof(TestClassForIDestructible)).Count());
        }