本文整理汇总了C#中UnityContainer.ResolveAll方法的典型用法代码示例。如果您正苦于以下问题:C# UnityContainer.ResolveAll方法的具体用法?C# UnityContainer.ResolveAll怎么用?C# UnityContainer.ResolveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityContainer
的用法示例。
在下文中一共展示了UnityContainer.ResolveAll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContainerReturnsEmptyArrayIfNoObjectsRegistered
public void ContainerReturnsEmptyArrayIfNoObjectsRegistered()
{
IUnityContainer container = new UnityContainer();
List<object> results = new List<object>(container.ResolveAll<object>());
Assert.IsNotNull(results);
CollectionAssert.AreEqual(new object[0], results);
}
示例2: ResolveAllReturnsRegisteredObjectsForBaseClass
public void ResolveAllReturnsRegisteredObjectsForBaseClass()
{
IUnityContainer container = new UnityContainer();
ILogger o1 = new MockLogger();
ILogger o2 = new SpecialLogger();
container
.RegisterInstance<ILogger>("o1", o1)
.RegisterInstance<ILogger>("o2", o2);
List<ILogger> results = new List<ILogger>(container.ResolveAll<ILogger>());
CollectionAssert.AreEqual(new ILogger[] {o1, o2}, results);
}
示例3: ResolveAllReturnsRegisteredObjects
public void ResolveAllReturnsRegisteredObjects()
{
IUnityContainer container = new UnityContainer();
object o1 = new object();
object o2 = new object();
container
.RegisterInstance<object>("o1", o1)
.RegisterInstance<object>("o2", o2);
List<object> results = new List<object>(container.ResolveAll<object>());
CollectionAssert.AreEqual(new object[] { o1, o2 }, results);
}
示例4: CanSetUpAnEmptyRule
public void CanSetUpAnEmptyRule()
{
// there is no visible effect for this, but it should still be resolved.
IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
// empty
container
.Configure<Interception>()
.AddPolicy("policy1");
List<InjectionPolicy> policies
= new List<InjectionPolicy>(container.ResolveAll<InjectionPolicy>());
Assert.AreEqual(2, policies.Count);
Assert.IsInstanceOfType(policies[0], typeof(AttributeDrivenPolicy));
Assert.IsInstanceOfType(policies[1], typeof(RuleDrivenPolicy));
Assert.AreEqual("policy1", policies[1].Name);
}
示例5: CanRegisterFactoryFunctionThatReceivesTypeAndName
public void CanRegisterFactoryFunctionThatReceivesTypeAndName()
{
Func<IUnityContainer, Type, string, object> factory = (c, t, s) => s + t.Name;
var container = new UnityContainer()
.RegisterType<string>("one", new InjectionFactory(factory))
.RegisterType<string>("two", new InjectionFactory(factory))
.RegisterType<string>("three", new InjectionFactory(factory));
var result = container.ResolveAll<string>();
result.AssertContainsInAnyOrder("oneString", "twoString", "threeString");
}
示例6: RegisteredFactoriesAreExecutedWhenDoingResolveAll
public void RegisteredFactoriesAreExecutedWhenDoingResolveAll()
{
var container = new UnityContainer()
.RegisterType<string>("one", new InjectionFactory(c => "this"))
.RegisterType<string>("two", new InjectionFactory(c => "that"))
.RegisterType<string>("three", new InjectionFactory(c => "the other"));
var result = container.ResolveAll<string>();
result.AssertContainsInAnyOrder("this", "that", "the other");
}
示例7: RegisteredFactoriesAreExecutedWhenDoingResolveAllWithOldAPI
public void RegisteredFactoriesAreExecutedWhenDoingResolveAllWithOldAPI()
{
var container = new UnityContainer()
.AddNewExtension<StaticFactoryExtension>()
.Configure<StaticFactoryExtension>()
.RegisterFactory<string>("one", c => "this")
.RegisterFactory<string>("two", c => "that" )
.RegisterFactory<string>("three", c => "the other")
.Container;
var result = container.ResolveAll<string>();
result.AssertContainsInAnyOrder("this", "that", "the other");
}