本文整理汇总了C#中Container.GetAll方法的典型用法代码示例。如果您正苦于以下问题:C# Container.GetAll方法的具体用法?C# Container.GetAll怎么用?C# Container.GetAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container.GetAll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: should_get_empty_enumerable_if_type_is_not_registered
public void should_get_empty_enumerable_if_type_is_not_registered()
{
var container = new Container();
var ints = container.GetAll<int>();
var strings = container.GetAll<string>();
ints.Should().BeEmpty();
strings.Should().BeEmpty();
}
示例2: should_support_instance_configuration
public void should_support_instance_configuration()
{
var types = new[] { typeof(Implementation1) };
var container1 = new Container(x => x.Scan.Types(types).AddConcreteSubClassesOf(typeof(IBaseType), y => y.Lifetime.Singleton()));
var instance1 = container1.GetAll<IBaseType>().Single();
var instance2 = container1.GetAll<IBaseType>().Single();
instance1.ShouldBe(instance2);
var container2 = new Container(x => x.Scan.Types(types).AddConcreteSubClassesOf<IBaseType>(y => y.Lifetime.Singleton()));
var instance3 = container2.GetAll<IBaseType>().Single();
var instance4 = container2.GetAll<IBaseType>().Single();
instance3.ShouldBe(instance4);
}
示例3: should_get_enumerable_containing_registered_instances
public void should_get_enumerable_containing_registered_instances()
{
var @int = 8;
var @string = "foobar";
var container = new Container(x =>
{
x.For<int>().Use(@int);
x.For<string>().Use(@string);
});
var ints = container.GetAll<int>();
var strings = container.GetAll<string>();
ints.Should().BeEquivalentTo(new[] { @int });
strings.Should().BeEquivalentTo(new[] { @string });
}
示例4: GetAll_should_throw_ActivationException
public void GetAll_should_throw_ActivationException()
{
var container = new Container(x => x.For<Alpha>().Use<Alpha>());
Should.Throw<ActivationException>(() => container.GetAll<Alpha>())
.InnerException.Message.ShouldBe(@"Cyclic dependency.
Maestro.Tests.resolve_type_with_cyclic_dependencies+Alpha
Maestro.Tests.resolve_type_with_cyclic_dependencies+Delta
Maestro.Tests.resolve_type_with_cyclic_dependencies+Charlie
Maestro.Tests.resolve_type_with_cyclic_dependencies+Beta
Maestro.Tests.resolve_type_with_cyclic_dependencies+Alpha");
}
示例5: should_register_concrete_sub_classes_of_provided_type
public void should_register_concrete_sub_classes_of_provided_type()
{
var types = new[] { typeof(Implementation1), typeof(Implementation2) };
var container = new Container(x => x.Scan.Types(types).AddConcreteSubClassesOf<IBaseType>());
var instances = container.GetAll<IBaseType>().ToList();
instances.Count.ShouldBe(2);
instances.OfType<Implementation1>().Count().ShouldBe(1);
instances.OfType<Implementation2>().Count().ShouldBe(1);
}
示例6: should_get_dependencies_with_same_name_as_top_instance_or_fall_back_to_default_instance
public void should_get_dependencies_with_same_name_as_top_instance_or_fall_back_to_default_instance()
{
var name1 = "abc";
var name2 = "xyz";
var grandChild = new GrandChild();
var grandChild1 = new GrandChild();
var container = new Container(x =>
{
x.For<ParentWithSingleChild>().Use<ParentWithSingleChild>().Set(y => y.Tag, grandChild);
x.For<ParentWithSingleChild>(name1).Use<ParentWithSingleChild>().Set(y => y.Tag, grandChild1);
x.For<ParentWithSingleChild>(name2).Use<ParentWithSingleChild>().Set(y => y.Tag, grandChild);
x.For<GrandChild>().Use(grandChild);
x.For<GrandChild>(name1).Use(grandChild1);
});
container.GetAll<ParentWithSingleChild>().Should().OnlyContain(x => x.Tag == x.Child.GrandChild);
}
示例7: should_try_to_get_dependencies_with_same_name_as_top_instance
public void should_try_to_get_dependencies_with_same_name_as_top_instance()
{
var @defaultDependency = "default";
var namedDependency = "named";
var name = "yada yada";
var container = new Container(x =>
{
x.For<Foo>().Add<Foo>();
x.For<Foo>(name).Use<Foo>();
x.For<object>().Use(@defaultDependency);
x.For<object>(name).Use(namedDependency);
});
var foos = container.GetAll<Foo>().ToList();
foos.Should().Contain(x => (string)x.Object == defaultDependency);
foos.Should().Contain(x => (string)x.Object == namedDependency);
}