本文整理匯總了C#中System.IocContainer.ResolveAll方法的典型用法代碼示例。如果您正苦於以下問題:C# IocContainer.ResolveAll方法的具體用法?C# IocContainer.ResolveAll怎麽用?C# IocContainer.ResolveAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IocContainer
的用法示例。
在下文中一共展示了IocContainer.ResolveAll方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ResolveAllByTypeNotRegisteredThrowsException
public void ResolveAllByTypeNotRegisteredThrowsException()
{
using (var container = new IocContainer())
{
var results = container.ResolveAll<IFoo>();
// Doesnt throw exception before it is enumerated because it uses yield return - OK ?
var test = results.Count();
}
}
示例2: ResolveAllByTypeReturnsInstancesOfExpectedType
public void ResolveAllByTypeReturnsInstancesOfExpectedType()
{
using (var container = new IocContainer())
{
container.Register<IFoo>(c => new Foo1());
container.Register<IFoo>("Foo1", c => new Foo2());
container.Register<IFoo>("Foo2", c => new Foo2());
container.Register<IBar>(c => new Bar1());
var results = container.ResolveAll<IFoo>();
Assert.IsTrue(results.Count() == 3);
var resultsList = results.ToList();
CollectionAssert.AllItemsAreNotNull(resultsList);
CollectionAssert.AllItemsAreInstancesOfType(resultsList, typeof(IFoo));
CollectionAssert.AllItemsAreUnique(resultsList);
}
}
示例3: RegisteredClassesCanBeResolvedAllByInterface
public void RegisteredClassesCanBeResolvedAllByInterface()
{
using (var iocContainer = new IocContainer())
{
iocContainer.Register<Foo1, Foo1>();
iocContainer.Register<Foo2, Foo2>();
iocContainer.Register<Bar1, Bar1>();
var results = iocContainer.ResolveAll<IFoo>();
Verify.That(results).IsNotNull()
.IsAnInstanceOfType(typeof(IEnumerable<IFoo>));
Verify.That(results.Count()).IsEqualTo(2);
}
}