本文整理汇总了C#中Container.ResolveAll方法的典型用法代码示例。如果您正苦于以下问题:C# Container.ResolveAll方法的具体用法?C# Container.ResolveAll怎么用?C# Container.ResolveAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container.ResolveAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldNotBuildTwice
public void ShouldNotBuildTwice()
{
var container = new Container();
container.Register<InterfaceA, ClassA1>();
container.Register<InterfaceA, ClassA2>();
var all = container.ResolveAll<InterfaceA>().ToArray();
var all2 = container.ResolveAll<InterfaceA>().ToArray();
Assert.AreEqual(2, all.Length);
Assert.AreEqual(2, all2.Length);
Assert.AreSame(all[0], all2[0]);
Assert.AreSame(all[1], all2[1]);
}
示例2: InitialiseContainerWithBootstrapper
private static IContainer InitialiseContainerWithBootstrapper(IBootstrapper containerBootstrapper)
{
IContainer container = new Container();
try
{
if (!ApplicationServiceLocator.IsInitializedSuccessfully)
{
ApplicationServiceLocator.InitializeAsync(container, containerBootstrapper).Wait();
}
else
{
container = ApplicationServiceLocator.Container;
}
}
catch (Exception exception)
{
Trace.TraceError(exception.Message);
}
DependencyResolver.SetResolver(
x => container.HasComponent(x) ? container.Resolve(x) : null,
x => container.HasComponent(x) ? container.ResolveAll(x) : new object[0]);
return container;
}
示例3: Should_resolve_all_instances
public void Should_resolve_all_instances()
{
// Arrange
IContainer container = new Container();
// Act & assert
var instancesBefore = container.ResolveAll<ITypeToResolve>();
Assert.That(instancesBefore.Count(), Is.EqualTo(0));
container.Register<ITypeToResolve>(ctx => new ConcreteType());
container.Register<ITypeToResolve>(ctx => new ConcreteType2());
container.Register<ITypeToResolve>(ctx => new ConcreteType3());
var instancesAfter = container.ResolveAll<ITypeToResolve>();
Assert.That(instancesAfter.Count(), Is.EqualTo(3));
}
示例4: ShouldRemoveExecutionContextInstanceOnly
public void ShouldRemoveExecutionContextInstanceOnly()
{
var instance1 = new TestClass();
var instance2 = new TestClass();
var container = new Container();
container.Inject<TestInterface>(instance1, Lifecycle.HttpContextOrExecutionContextLocal);
TestInterface[] thread2ResolvedTestClasses = null;
bool thread2HasRegistration = true;
ExecutionContext.SuppressFlow();
var thread2 = new Thread(() =>
{
container.Inject<TestInterface>(instance2, Lifecycle.HttpContextOrExecutionContextLocal);
thread2ResolvedTestClasses = container.ResolveAll<TestInterface>().ToArray();
container.RemoveInstancesOf<TestInterface>(Lifecycle.HttpContextOrExecutionContextLocal);
thread2HasRegistration = container.HasRegistrationFor<TestInterface>();
});
thread2.Start();
thread2.Join(1000);
ExecutionContext.RestoreFlow();
Assert.IsFalse(thread2HasRegistration);
Assert.AreEqual(1, thread2ResolvedTestClasses.Length);
Assert.AreEqual(instance1, container.Resolve<TestInterface>());
}
示例5: ShouldReturnEmptyEnumerable
public void ShouldReturnEmptyEnumerable()
{
var container = new Container();
var xs = container.ResolveAll<InterfaceA>();
Assert.AreEqual(0, xs.Count());
}
示例6: ShouldRemoveInstances
public void ShouldRemoveInstances()
{
var container = new Container();
container.Inject<InterfaceA>(new ClassA1());
container.Register<InterfaceA, ClassA2>();
container.RemoveAllRegistrationsAndInstancesOf<InterfaceA>();
Assert.AreEqual(0, container.ResolveAll<InterfaceA>().Count());
}
示例7: ShouldResolveAll
public void ShouldResolveAll()
{
var container = new Container();
container.Register<InterfaceA, ClassA1>();
container.Register<InterfaceA, ClassA2>();
var all = container.ResolveAll<InterfaceA>().ToArray();
Assert.AreEqual(2, all.Length);
Assert.IsInstanceOf<ClassA1>(all[0]);
Assert.IsInstanceOf<ClassA2>(all[1]);
}
示例8: ShouldConstruct
public void ShouldConstruct()
{
var container = new Container();
container.RunAllTypeProcessors();
var instances = container.ResolveAll<TestInterface>().ToArray();
Assert.AreEqual(typeof(TestClass1), instances[0].GetType());
Assert.AreEqual(typeof(TestClass2), instances[1].GetType());
Assert.AreEqual(typeof(TestClass3), instances[2].GetType());
}
示例9: Should_resolve_instances_from_primary_source
public void Should_resolve_instances_from_primary_source()
{
// Arrange
var expectedInstances = new List<object> { new ConcreteType3(), new ConcreteType3() };
IContainer container = new Container();
container.SetPrimarySource(ctx => new FakeContainerSource(expectedInstances));
// Act
var instance = container.ResolveAll(typeof(ConcreteType3));
// Assert
Assert.That(instance, Is.EqualTo(expectedInstances));
}
示例10: ShouldResolveSameInstance
public void ShouldResolveSameInstance()
{
var container = new Container();
container.Register<TestInterface>(c => new TestClass());
var resolved1 = container.Resolve<TestInterface>();
var resolved2 = container.Resolve<TestInterface>();
var resolvedAll = container.ResolveAll<TestInterface>().ToArray();
Assert.AreEqual(1, resolvedAll.Length);
Assert.AreSame(resolved1, resolved2);
}
示例11: ShouldResolveRegisteredAndInjected
public void ShouldResolveRegisteredAndInjected()
{
var container = new Container();
container.Register<TestInterface, TestClass>();
var testClass = new TestClass2();
container.Inject<TestInterface>(testClass);
var instances = container.ResolveAll<TestInterface>().ToArray();
Assert.AreEqual(2, instances.Length);
Assert.AreNotSame(instances[0], instances[1]);
}
示例12: ShouldThrowWhenNoRegistrations
public void ShouldThrowWhenNoRegistrations()
{
var container = new Container();
try
{
container.ResolveAll<InterfaceA>().ToArray();
}
catch(ContainerException e)
{
Assert.AreEqual("No types registered for `NanoIoC.Tests.MultipleRegistrations+InterfaceA, NanoIoC.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null`", e.Message);
}
}
示例13: Should_return_empty_list_when_resolving_type_that_is_not_registered
public void Should_return_empty_list_when_resolving_type_that_is_not_registered()
{
// Arrange
IContainer container = new Container();
// Act
var instances = container.ResolveAll(typeof(ConcreteType));
// Assert
Assert.That(instances, Is.Not.Null);
Assert.That(instances, Is.InstanceOf(typeof(IEnumerable<object>)));
}
示例14: CanResolveAll
public void CanResolveAll()
{
// Arrange
var sut = new Container();
sut.Register<C, IC>(new C());
sut.Register<B, IB>();
sut.Register<A, IA>(c => new A(c.Resolve<IB>(), c.Resolve<IC>()));
sut.Register<A2, IA>();
// Assert
var allA = sut.ResolveAll<IA>();
Assert.NotEmpty(allA);
Assert.Equal(2, allA.Count());
}
示例15: Non_Generic_Named_ResolveAll_Returns_Correct_Services
public void Non_Generic_Named_ResolveAll_Returns_Correct_Services()
{
var target = new Container();
target.Register<ISimpleTestService>(c => new SimpleTestService());
target.Register<ISimpleTestService>("Second", c => new SecondSimpleTestService());
var allResolved = target.ResolveAll(typeof(ISimpleTestService)).ToArray();
var simpleTestServicesResolved = allResolved.OfType<SimpleTestService>().ToArray();
var secondSimpleTestServicesResolved = allResolved.OfType<SecondSimpleTestService>().ToArray();
Assert.AreEqual(2, allResolved.Length);
Assert.AreEqual(1, simpleTestServicesResolved.Length);
Assert.AreEqual(1, secondSimpleTestServicesResolved.Length);
}