本文整理匯總了C#中System.IocContainer.TryResolveAll方法的典型用法代碼示例。如果您正苦於以下問題:C# IocContainer.TryResolveAll方法的具體用法?C# IocContainer.TryResolveAll怎麽用?C# IocContainer.TryResolveAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IocContainer
的用法示例。
在下文中一共展示了IocContainer.TryResolveAll方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TryResolveAllReturnsExpectedInstances
public void TryResolveAllReturnsExpectedInstances()
{
using (var container = new IocContainer())
{
// Arrange
var foo1 = new Foo1();
var foo2 = new Foo2();
var foo3 = new Foo2();
var bar1 = new Bar1();
container.RegisterInstance<IFoo>(foo1);
container.RegisterInstance<IFoo>("Foo1", foo2);
container.RegisterInstance<IFoo>("Foo2", foo3);
container.RegisterInstance<IBar>(bar1);
// Act
var results = container.TryResolveAll<IFoo>();
var resultList = results.ToList();
// Assert
Assert.IsTrue(results.Count() == 3);
CollectionAssert.Contains(resultList, foo1);
CollectionAssert.Contains(resultList, foo2);
CollectionAssert.Contains(resultList, foo3);
}
}
示例2: TryResolveAllByTypeNotRegisteredReturnsEmptyEnumerable
public void TryResolveAllByTypeNotRegisteredReturnsEmptyEnumerable()
{
using (var container = new IocContainer())
{
// Arrange
var foo1 = new Foo1();
var foo2 = new Foo2();
var bar1 = new Bar1();
container.RegisterInstance<IFoo>(foo1);
container.RegisterInstance<IFoo>("Foo", foo2);
container.RegisterInstance<IBar>(bar1);
// Act
var results = container.TryResolveAll<IFooBar>();
// Assert
Assert.IsTrue(results.Count() == 0);
}
}