本文整理汇总了C#中Funq.Container.CreateChildContainer方法的典型用法代码示例。如果您正苦于以下问题:C# Container.CreateChildContainer方法的具体用法?C# Container.CreateChildContainer怎么用?C# Container.CreateChildContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Funq.Container
的用法示例。
在下文中一共展示了Container.CreateChildContainer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_use_child_containers
public void Can_use_child_containers()
{
Container parent = new Container();
// Create two childs, each with a specific instance Dependancy
Container child1 = parent.CreateChildContainer();
Container child2 = parent.CreateChildContainer();
child1.Register(new Dependency("First"));
child2.Register(new Dependency("Second"));
// Now register two factories for ISomeService.
child1.Register<ISomeService>(x => Factory(x));
child2.Register<ISomeService>(x => Factory(x));
ISomeService resolved1 = child1.Resolve<ISomeService>();
ISomeService resolved2 = child2.Resolve<ISomeService>();
Assert.That(((SomeService)resolved1).dependancy.label, Is.EqualTo("First"));
Assert.That(((SomeService)resolved2).dependancy.label, Is.EqualTo("Second"));
}
示例2: TestFunqChildContainer
public void TestFunqChildContainer()
{
using (var fakeThings = new FakeThingsRepository()){
var mike = fakeThings.SetupMike();
using(var container = new Container())
{
container.Register<IThingsRepository>(fakeThings);
using (var container2 = container.CreateChildContainer())
{
var things = container2.Resolve<IThingsRepository>().GetByName(new string[]{"Mike"});
Assert.That(things.First(),Is.EqualTo(mike));
}
}
}
}