当前位置: 首页>>代码示例>>C#>>正文


C# Container.Dispose方法代码示例

本文整理汇总了C#中Container.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Container.Dispose方法的具体用法?C# Container.Dispose怎么用?C# Container.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Container的用法示例。


在下文中一共展示了Container.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: T03_Dispose_Other

        public void T03_Dispose_Other()
        {
            var container = new Container(defaultLifestyle: DefaultLifestyle.Singleton, log: Write);
            container.RegisterTransient<ClassA>();
            var instance = container.Resolve<ClassA>();
            container.Dispose();
            Assert.False(instance.IsDisposed);

            container.RegisterFactory(() => instance);
            container.Dispose();
            Assert.False(instance.IsDisposed);
        }
开发者ID:dshe,项目名称:StandardContainer,代码行数:12,代码来源:DisposeTest.cs

示例2: GCCollect_OnUnreferencedVerifiedContainersWithDecorators_CollectsThoseContainers

        public void GCCollect_OnUnreferencedVerifiedContainersWithDecorators_CollectsThoseContainers()
        {
            // Arrange
            Func<Container> buildContainer = () =>
            {
                var container = new Container();
                container.Options.EnableDynamicAssemblyCompilation = false;
                container.Register<INonGenericService, RealNonGenericService>();

                container.RegisterDecorator<INonGenericService, NonGenericServiceDecorator>();

                container.GetInstance<INonGenericService>();

                container.Dispose();

                return container;
            };

            var containers =
                Enumerable.Range(0, 10).Select(_ => new WeakReference(buildContainer())).ToArray();

            // Act
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            // Assert
            Assert.AreEqual(0, containers.Count(c => c.IsAlive), "We've got a memory leak.");
        }
开发者ID:khellang,项目名称:SimpleInjector,代码行数:29,代码来源:ConsistencyTests.cs

示例3: DoTest

        public override TestResult DoTest(ITestCase testCase, int testCasesNumber, bool singleton)
        {
            var result = new TestResult { Singleton = singleton, TestCasesNumber = testCasesNumber };
            var sw = new Stopwatch();

            var c = new Container();
            if (singleton)
            {
                sw.Start();
                c = (Container)testCase.SingletonRegister(c);
                sw.Stop();
            }
            else
            {
                sw.Start();
                c = (Container)testCase.TransientRegister(c);
                sw.Stop();
            }
            result.RegisterTime = sw.ElapsedMilliseconds;

            sw.Reset();
            result.ResolveTime = DoResolve(sw, testCase, c, testCasesNumber, singleton);

            c.Dispose();

            return result;
        }
开发者ID:amularczyk,项目名称:NiquIoC,代码行数:27,代码来源:StructureMapPerformance.cs

示例4: T02_Dispose_Instance

 public void T02_Dispose_Instance()
 {
     var container = new Container(defaultLifestyle: DefaultLifestyle.Singleton, log: Write);
     var instance = new ClassA();
     container.RegisterInstance(instance);
     container.Dispose();
     Assert.True(instance.IsDisposed);
 }
开发者ID:dshe,项目名称:StandardContainer,代码行数:8,代码来源:DisposeTest.cs

示例5: T01_Dispose_Singleton

 public void T01_Dispose_Singleton()
 {
     var container = new Container(defaultLifestyle: DefaultLifestyle.Singleton, log: Write);
     container.RegisterSingleton<ClassA>();
     var instance = container.Resolve<ClassA>();
     container.Dispose();
     Assert.True(instance.IsDisposed);
 }
开发者ID:dshe,项目名称:StandardContainer,代码行数:8,代码来源:DisposeTest.cs

示例6: disposing_a_main_container_will_dispose_an_object_injected_into_the_container

        public void disposing_a_main_container_will_dispose_an_object_injected_into_the_container()
        {
            var disposable = new C2Yes();
            var container = new Container(x => x.For<C2Yes>().Use(disposable));

            container.Dispose();

            disposable.WasDisposed.ShouldBeTrue();
        }
开发者ID:slahn,项目名称:structuremap,代码行数:9,代码来源:ContainerDisposalTester.cs

示例7: main_container_should_dispose_singletons

        public void main_container_should_dispose_singletons()
        {
            var container = new Container(x => { x.ForSingletonOf<C1Yes>().Use<C1Yes>(); });

            var single = container.GetInstance<C1Yes>();

            container.Dispose();

            single.WasDisposed.ShouldBeTrue();
        }
开发者ID:slahn,项目名称:structuremap,代码行数:10,代码来源:ContainerDisposalTester.cs

示例8: container_scoping_with_root_child_and_nested_container

        public void container_scoping_with_root_child_and_nested_container()
        {
            var container = new Container(_ =>
            {
                _.ForConcreteType<Disposable>().Configure.ContainerScoped();
            });

            var child = container.CreateChildContainer();

            var nested = container.GetNestedContainer();

            // Always the same object when requested from the root container
            var mainDisposable = container.GetInstance<Disposable>();
            mainDisposable
                .ShouldBeTheSameAs(container.GetInstance<Disposable>());

            // Always the same object when requested from a child container
            var childDisposable = child.GetInstance<Disposable>();
            childDisposable
                .ShouldBeTheSameAs(child.GetInstance<Disposable>());

            // Always the same object when requested from a nested container
            var nestedDisposable = nested.GetInstance<Disposable>();
            nestedDisposable
                .ShouldBeTheSameAs(nested.GetInstance<Disposable>());

            // It should be a different object instance for
            // all three containers
            mainDisposable
                .ShouldNotBeTheSameAs(childDisposable);

            mainDisposable
                .ShouldNotBeTheSameAs(nestedDisposable);

            childDisposable
                .ShouldNotBeTheSameAs(nestedDisposable);

            // When the nested container is disposed,
            // it should dispose all the container scoped objects,
            // but not impact the other containers
            nested.Dispose();
            nestedDisposable.WasDisposed.ShouldBeTrue();
            childDisposable.WasDisposed.ShouldBeFalse();
            mainDisposable.WasDisposed.ShouldBeFalse();

            // Same for the child container
            child.Dispose();
            childDisposable.WasDisposed.ShouldBeTrue();
            mainDisposable.WasDisposed.ShouldBeFalse();

            // Same for the main container
            container.Dispose();
            mainDisposable.WasDisposed.ShouldBeTrue();
        }
开发者ID:khellang,项目名称:structuremap,代码行数:54,代码来源:container_scoping.cs

示例9: Container

            something_in_the_middle_of_container_that_tries_to_dispose_container_will_not_blow_everything_up_with_a_stack_overflow_exception
            ()
        {
            var container =
                new Container(x => { x.ForSingletonOf<ITryToDisposeContainer>().Use<ITryToDisposeContainer>(); });

            // just want it spun up
            container.GetInstance<ITryToDisposeContainer>();

            container.Dispose();
        }
开发者ID:slahn,项目名称:structuremap,代码行数:11,代码来源:ContainerDisposalTester.cs

示例10: singletons_are_disposed_when_the_container_is_disposed

        public void singletons_are_disposed_when_the_container_is_disposed()
        {
            var container = new Container(_ => { _.ForSingletonOf<DisposableSingleton>(); });

            var singleton = container.GetInstance<DisposableSingleton>();
            singleton.WasDisposed.ShouldBeFalse();

            // now, dispose the Container
            container.Dispose();

            // the singleton scoped object should be disposed
            singleton.WasDisposed.ShouldBeTrue();
        }
开发者ID:RANENTONG,项目名称:structuremap,代码行数:13,代码来源:lifecycle_creation.cs

示例11: ContainerOwnedAndContainerReusedInstacesAreDisposed

        public void ContainerOwnedAndContainerReusedInstacesAreDisposed()
        {
            var container = new Container();
            container.Register<IFoo>(c => new Disposable())
                .ReusedWithin(ReuseScope.Container)
                .OwnedBy(Owner.Container);

            var foo = container.Resolve<IFoo>() as Disposable;

            container.Dispose();

            Assert.IsTrue(foo.IsDisposed);
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:13,代码来源:ContainerFixture.cs

示例12: tracks_transients_built_as_dependencies_in_graph

        public void tracks_transients_built_as_dependencies_in_graph()
        {
            var container = new Container(_ => _.TransientTracking = TransientTracking.ExplicitReleaseMode);

            var root = container.GetInstance<Grandparent>();
            var parent = root.Parent;
            var guy = parent.Guy;

            container.TransientTracking.Tracked.ShouldHaveTheSameElementsAs(guy, parent);

            container.Dispose();

            parent.WasDisposed.ShouldBeTrue();
            guy.WasDisposed.ShouldBeTrue();
        }
开发者ID:slahn,项目名称:structuremap,代码行数:15,代码来源:transient_tracking_mode_specs.cs

示例13: the_order

        public void the_order()
        {
            var container = new Container();

            using (var runtime = FubuTransport.For<Defaults>().StructureMap(container).Bootstrap())
            {
                var handlers = container.GetInstance<IHandlerPipeline>().ShouldBeOfType<HandlerPipeline>().Handlers;

                container.Dispose();
                handlers[0].ShouldBeOfType<DelayedEnvelopeHandler>();
                handlers[1].ShouldBeOfType<ResponseEnvelopeHandler>();
                handlers[2].ShouldBeOfType<ChainExecutionEnvelopeHandler>();
                handlers[3].ShouldBeOfType<NoSubscriberHandler>();
            }
        }
开发者ID:RyanHauert,项目名称:FubuTransportation,代码行数:15,代码来源:envelope_handlers_are_registered_in_the_right_order.cs

示例14: disposing_the_container_disposes_tracked_transients

        public void disposing_the_container_disposes_tracked_transients()
        {
            var container = new Container(_ => _.TransientTracking = TransientTracking.ExplicitReleaseMode);

            var transient1 = container.GetInstance<DisposableGuy>();
            var transient2 = container.GetInstance<DisposableGuy>();

            transient1.WasDisposed.ShouldBeFalse();
            transient2.WasDisposed.ShouldBeFalse();

            container.Dispose();

            transient1.WasDisposed.ShouldBeTrue();
            transient2.WasDisposed.ShouldBeTrue();
        }
开发者ID:slahn,项目名称:structuremap,代码行数:15,代码来源:transient_tracking_mode_specs.cs

示例15: object_is_not_disposed_in_nested_container

        public void object_is_not_disposed_in_nested_container()
        {
            var guy = new DisposableGuy();

            var container = new Container(x => { x.For<DisposableGuy>().Use(guy); });

            using (var nested = container.GetNestedContainer())
            {
            }

            guy.WasDisposed.ShouldBeFalse();

            container.Dispose();

            guy.WasDisposed.ShouldBeTrue();
        }
开发者ID:goraw,项目名称:structuremap,代码行数:16,代码来源:ObjectInstanceTester.cs


注:本文中的Container.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。