コード例 #1
0
        public void CloneTest()
        {
            WeakSingletonLifestyle container = new WeakSingletonLifestyle();

            ILifestyle clone = container.Clone();

            Assert.NotNull(clone);
            Assert.IsType(typeof(WeakSingletonLifestyle), clone);
        }
コード例 #2
0
        private int GetBasicServiceCount(WeakSingletonLifestyle container, int count)
        {
            IBasicService basicService = (IBasicService)container.Locate(
                (x, y) => new BasicService { Count = count },
                new FauxInjectionScope(),
                new FauxInjectionContext(),
                null);

            Assert.NotNull(basicService);

            return basicService.Count;
        }
コード例 #3
0
        public void WeakReferenceTest()
        {
            WeakSingletonLifestyle container = new WeakSingletonLifestyle();

            int count = GetBasicServiceCount(container, 1);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            int count2 = GetBasicServiceCount(container, 2);

            Assert.Equal(2, count2);
        }
コード例 #4
0
        public void ShareTest()
        {
            WeakSingletonLifestyle container = new WeakSingletonLifestyle();

            object basicService = container.Locate((x, y) => new BasicService(),
                new FauxInjectionScope(),
                new FauxInjectionContext(),
                null);

            Assert.NotNull(basicService);

            object basicService2 = container.Locate((x, y) => new BasicService(),
                new FauxInjectionScope(),
                new FauxInjectionContext(),
                null);

            Assert.True(ReferenceEquals(basicService, basicService2));
        }
コード例 #5
0
        public void TransientTest()
        {
            WeakSingletonLifestyle container = new WeakSingletonLifestyle();

            Assert.False(container.Transient);
        }
コード例 #6
0
        public void DisposeTest()
        {
            WeakSingletonLifestyle container = new WeakSingletonLifestyle();

            container.Dispose();
        }