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


C# DependencyInjectionContainer.CreateChildScope方法代码示例

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


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

示例1: SingletonPerNamedScopeBasicTest

        public void SingletonPerNamedScopeBasicTest()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            container.Configure(c => c.Export<BasicService>().As<IBasicService>().Lifestyle.SingletonPerNamedScope("Test"));

            var childScope = container.CreateChildScope(scopeName: "Test");

            IBasicService basicService = childScope.Locate<IBasicService>();

            Assert.NotNull(basicService);

            Assert.Same(basicService, childScope.Locate<IBasicService>());
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:14,代码来源:SingletonPerNamedScopeTests.cs

示例2: SingletonPerNamedScopeDisposal

        public void SingletonPerNamedScopeDisposal()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            container.Configure(c => c.Export<DisposableService>().As<IDisposableService>().Lifestyle.SingletonPerNamedScope("Test"));

            bool disposed = false;

            using (var childScope = container.CreateChildScope(scopeName: "Test"))
            {
                childScope.Locate<IDisposableService>().Disposing += (sender, args) => disposed = true;
            }

            Assert.True(disposed);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:15,代码来源:SingletonPerNamedScopeTests.cs

示例3: ResolveFromChildScope

		public void ResolveFromChildScope()
		{
			DependencyInjectionContainer container = new DependencyInjectionContainer();

			SimpleSecondaryExportLocator resolver = new SimpleSecondaryExportLocator();

			container.AddSecondaryLocator(resolver);
			container.Configure(c => c.Export<ImportConstructorService>().As<IImportConstructorService>());

			resolver.AddResolveValue((IBasicService)new BasicService());

			IInjectionScope childScope = container.CreateChildScope();

			IImportConstructorService constructorService = childScope.Locate<IImportConstructorService>();

			Assert.NotNull(constructorService);
		}
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:17,代码来源:SecondaryDependencyResolverTests.cs

示例4: WhatDoIHaveTestDoNotIncludeParent

        public void WhatDoIHaveTestDoNotIncludeParent()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            container.Configure(c => c.Export<ConstructorImportService>());

            using (IInjectionScope child = container.CreateChildScope(c => c.Export<BasicService>().As<IBasicService>().AndSingleton()))
            {
                string whatDoIHave = child.WhatDoIHave();

                Console.Write(whatDoIHave);

                Assert.NotNull(whatDoIHave);

                Assert.Contains("BasicService", whatDoIHave);
                Assert.DoesNotContain("ConstructorImportService", whatDoIHave);
            }
        }
开发者ID:jrjohn,项目名称:Grace,代码行数:18,代码来源:IExportLocatorExtensionsTests.cs

示例5: WhatDoIHaveFilteredTest

		public void WhatDoIHaveFilteredTest()
		{
			DependencyInjectionContainer container = new DependencyInjectionContainer();

			container.Configure(c => c.Export<ConstructorImportService>());

			using (IInjectionScope child = container.CreateChildScope(c => c.Export<BasicService>().As<IBasicService>().Lifestyle.Singleton()))
			{
				string whatDoIHave = child.WhatDoIHave(includeParent: true, consider: ExportsThat.AreExportedAs<IBasicService>());

				Console.Write(whatDoIHave);

				Assert.NotNull(whatDoIHave);

				Assert.Contains("BasicService", whatDoIHave);
				Assert.DoesNotContain("ConstructorImportService", whatDoIHave);
			}
		}
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:18,代码来源:IExportLocatorExtensionsTests.cs

示例6: PropertyInjectorInspectorChildScope

        public void PropertyInjectorInspectorChildScope()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            container.AddStrategyInspector(new PropertyInjectionInspector<IBasicService>());

            var child = container.CreateChildScope();

            child.Configure(c =>
            {
                c.Export<BasicService>().As<IBasicService>();
                c.Export<ImportPropertyService>().As<IImportPropertyService>();
            });

            IImportPropertyService propertyService = child.Locate<IImportPropertyService>();

            Assert.NotNull(propertyService);
            Assert.NotNull(propertyService.BasicService);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:19,代码来源:AdvancedContainerTests.cs

示例7: MissingExportFromChildScopeTest

        public void MissingExportFromChildScopeTest()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            container.Configure(c => c.Export<ImportConstructorService>().As<IImportConstructorService>());

            container.ResolveUnknownExports += (sender, args) =>
                                               {
                                                   args.ExportedValue = new BasicService();
                                               };

            IInjectionScope childScope = container.CreateChildScope();

            IImportConstructorService constructorService = childScope.Locate<IImportConstructorService>();

            Assert.NotNull(constructorService);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:17,代码来源:BasicContainerTests.cs

示例8: SingletonPerScopeNamedDifferentNamedScopes

        public void SingletonPerScopeNamedDifferentNamedScopes()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer();

            container.Configure(c => c.Export<BasicService>().As<IBasicService>().Lifestyle.SingletonPerNamedScope("Test"));

            var child1 = container.CreateChildScope(scopeName: "Test");

            IBasicService baseService1 = child1.Locate<IBasicService>();

            Assert.NotNull(baseService1);

            Assert.Same(baseService1, child1.Locate<IBasicService>());

            var child2 = container.CreateChildScope(scopeName: "Test");

            IBasicService baseService2 = child2.Locate<IBasicService>();

            Assert.NotNull(baseService2);

            Assert.Same(baseService2, child2.Locate<IBasicService>());

            Assert.NotSame(baseService1, baseService2);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:24,代码来源:SingletonPerNamedScopeTests.cs


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