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


C# DependencyInjectionContainer.LocateAll方法代码示例

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


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

示例1: BulkLocateWithKey

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

            container.Configure(c => c.Export(Types.FromThisAssembly())
                                      .ByInterface<ISimpleObject>()
                                      .WithKey(t => t.Name.Last()));

            container.Configure(c =>
            {
                foreach (char ch in "ABCDE")
                {
                    c.Export<ImportSingleSimpleObject>()
                     .WithKey(ch)
                     .WithCtorParam<ISimpleObject>()
                     .LocateWithKey(ch);
                }
            });

            ImportSingleSimpleObject single = container.Locate<ImportSingleSimpleObject>(withKey: 'A');

            Assert.NotNull(single);
            Assert.IsType<SimpleObjectA>(single.SimpleObject);

            Assert.Equal(3, container.LocateAll<ImportSingleSimpleObject>(withKey: new[] { 'A', 'C', 'E' }).Count);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:26,代码来源:KeyedTests.cs

示例2: Main

		static int Main(string[] args)
		{
			DependencyInjectionContainer container = new DependencyInjectionContainer();

			container.Configure(c => c.Export(Types.FromThisAssembly()).
											   ByInterface(typeof(IExampleModule)).
											   ByInterface(typeof(IExampleSubModule<>)).
											   ByInterface(typeof(IExample<>)));

			IEnumerable<IExampleModule> exampleModules = container.LocateAll<IExampleModule>();

			try
			{
				foreach (IExampleModule exampleModule in exampleModules)
				{
					exampleModule.Execute();
				}
			}
			catch (Exception exp)
			{
				Console.WriteLine("Exception thrown");
				Console.WriteLine(exp.Message);

			    return -1;
			}

		    return 0;
		}
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:28,代码来源:Program.cs

示例3: InEnvironment

        public void InEnvironment()
        {
            DependencyInjectionContainer container = new DependencyInjectionContainer(ExportEnvironment.UnitTest);

            container.Configure(c => c.ExportAssembly(GetType().Assembly).InEnvironment(ExportEnvironment.RunTimeOnly));

            IEnumerable<ISimpleObject> simpleObjects = container.LocateAll<ISimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(0, simpleObjects.Count());
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:11,代码来源:ExportAssemblyConfigurationTests.cs

示例4: SelectTypes

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

            container.Configure(
                c => c.ExportAssembly(GetType().Assembly).ByInterface(typeof(ISimpleObject)).Select(TypesThat.EndWith("C")));

            IEnumerable<ISimpleObject> simpleObjects = container.LocateAll<ISimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(1, simpleObjects.Count());
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:12,代码来源:ExportAssemblyConfigurationTests.cs

示例5: ExportInterfaces

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

            container.Configure(
                c => c.ExportAssembly(GetType().Assembly).ByInterfaces(t => t.Name.StartsWith("ISimple")));

            IEnumerable<ISimpleObject> simpleObjects = container.LocateAll<ISimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(5, simpleObjects.Count());
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:12,代码来源:ExportAssemblyConfigurationTests.cs

示例6: BasedOnInterfaceTest

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

            container.Configure(c => c.Export(Types.FromThisAssembly())
                                              .BasedOn<ISimpleObject>()
                                              .ByInterfaces());

            IEnumerable<ISimpleObject> simpleObjects = container.LocateAll<ISimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(5, simpleObjects.Count());
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:13,代码来源:AdvancedContainerTests.cs

示例7: ComplexHaveAttribute

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

            container.Configure(c => c.Export(Types.FromThisAssembly()).
                ByInterface(typeof(IAttributedSimpleObject)).
                Select(TypesThat.HaveAttribute<SomeTestAttribute>()));

            IEnumerable<IAttributedSimpleObject> simpleObjects = container.LocateAll<IAttributedSimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(3, simpleObjects.Count());
        }
开发者ID:jrjohn,项目名称:Grace,代码行数:13,代码来源:TypesThatTests.cs

示例8: ExportInterfacesAndWhere

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

            container.Configure(
                c => c.Export(Types.FromThisAssembly()).
                    ByInterfaces(TypesThat.StartWith("ISimple")).
                    Select(TypesThat.EndWith("C")));

            IEnumerable<ISimpleObject> simpleObjects = container.LocateAll<ISimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(1, simpleObjects.Count());
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:14,代码来源:ExportAssemblyConfigurationTests.cs

示例9: LocateIEnumerableLazy

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

			container.Configure(c => c.Export<LazyService>().As<ILazyService>());

			LazyService.Created = false;

			List<Lazy<ILazyService>> lazies = container.LocateAll<Lazy<ILazyService>>();

			Assert.NotNull(lazies);
			Assert.False(LazyService.Created);

			ILazyService service = lazies.First().Value;

			Assert.NotNull(service);
			Assert.True(LazyService.Created);
		}
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:18,代码来源:LazyTests.cs

示例10: OwnedCollection

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

            container.Configure(c => c.Export<DisposableService>().As<IDisposableService>());

            List<Owned<IDisposableService>> ownedList =
                container.LocateAll<Owned<IDisposableService>>();

            Assert.NotNull(ownedList);
            Assert.Equal(1, ownedList.Count);
            Assert.NotNull(ownedList[0].Value);

            bool disposedCalled = false;

            ownedList[0].Value.Disposing += (sender, args) => disposedCalled = true;

            ownedList[0].Dispose();

            Assert.True(disposedCalled);
        }
开发者ID:jrjohn,项目名称:Grace,代码行数:21,代码来源:OwnedTests.cs

示例11: WithInspectorFor

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

            container.Configure(c => c.Export(Types.FromThisAssembly())
                                      .ByInterfaces()
                                      .WithInspectorFor<ISimpleObject>(e => e.AddMetadata("SimpleObject", e.ActivationType)));

            var list =
                container.LocateAll<ISimpleObject>(consider: ExportsThat.HaveMetadata("SimpleObject"));

            Assert.Equal(5, list.Count);

            list =
                container.LocateAll<ISimpleObject>(consider:
                    ExportsThat.HaveMetadata("SimpleObject", typeof(SimpleObjectA)));

            Assert.Equal(1, list.Count);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:19,代码来源:AdvancedContainerTests.cs

示例12: TypesThatHaveAttributeFilter

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

            container.Configure(c => c.Export(Types.FromThisAssembly())
                                      .ByInterfaces()
                                      .Select(TypesThat.HaveAttribute(TypesThat.StartWith("Simple"))));

            List<ISimpleObject> simpleObjects = container.LocateAll<ISimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(3, simpleObjects.Count);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:13,代码来源:AdvancedContainerTests.cs

示例13: TypesThatAreBasedOnComplexChainedFilter

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

            container.Configure(c => c.Export(Types.FromThisAssembly())
                                      .ByInterfaces()
                                      .Select(TypesThat.AreBasedOn(TypesThat.StartWith("ISimple"))));

            List<ISimpleObject> simpleObjects = container.LocateAll<ISimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(5, simpleObjects.Count);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:13,代码来源:AdvancedContainerTests.cs

示例14: ImportKeyedBulkTest

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

            container.Configure(c => c.Export(Types.FromThisAssembly())
                                      .ByInterface<ISimpleObject>()
                                      .WithKey(t => t.Name.Last()));

            container.Configure(c => c.Export(Types.FromThisAssembly())
                                      .ByInterfaces()
                                      .Select(TypesThat.AreBasedOn<IImportKeyed>())
                                      .WithKey(t => t.Name.Last())
                                      .WithCtorParam<ISimpleObject>().LocateWithKey(t => t.Name.Last()));

            IImportKeyed importKeyedA = container.Locate<IImportKeyed>(withKey: 'A');

            Assert.NotNull(importKeyedA);
            Assert.IsType<SimpleObjectA>(importKeyedA.SimpleObject);

            Assert.Equal(3, container.LocateAll<IImportKeyed>(withKey: new[] { 'A', 'C', 'E' }).Count);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:21,代码来源:KeyedTests.cs

示例15: TypesThatAreBasedOnChainedFilter

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

            container.Configure(c => c.Export(Types.FromThisAssembly())
                                      .ByInterfaces()
                                      .Select(TypesThat.AreBasedOn<ISimpleObject>().And.HaveAttribute<SimpleFilterAttribute>()));

            List<ISimpleObject> simpleObjects = container.LocateAll<ISimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(3, simpleObjects.Count);
        }
开发者ID:ricardoshimoda,项目名称:Grace,代码行数:13,代码来源:AdvancedContainerTests.cs


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