本文整理汇总了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);
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}