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")); }
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)); } } } }