public void BindPerKey_WithAndWithoutParam_DifferentInstances() { var k = new StandardKernel(); k.BindPerKey <int, IFoo, Foo>(); k.BindPerKey <int, string, IFoo, Foo>(); var factoryA = k.Get <Func <int, IFoo> >(); var factoryB = k.Get <Func <int, string, IFoo> >(); factoryA(1).ShouldNotBeSameAs(factoryB(1, "red")); }
private void Test_BindPerKey <TService, TImplementation>() where TImplementation : TService { var k = new StandardKernel(); k.BindPerKey <int, TService, TImplementation>(); k.Get <TService>().ShouldBeOfType <TImplementation>(); Func <Func <int, TService> > metafactory = () => k.Get <Func <int, TService> >(); var factory = metafactory(); factory(1).ShouldBeSameAs(factory(1)); factory(1).ShouldNotBeSameAs(factory(2)); metafactory()(1).ShouldBeSameAs(metafactory()(1)); metafactory()(1).ShouldNotBeSameAs(metafactory()(2)); }
private void Test_BindPerKeyWithParam <TService, TImplementation>() where TImplementation : TService { var k = new StandardKernel(); k.BindPerKey <int, string, TService, TImplementation>(); k.Get <TService>().ShouldBeOfType <TImplementation>(); Func <Func <int, string, TService> > metafactory = () => k.Get <Func <int, string, TService> >(); var factory = metafactory(); var blue = factory(1, "blue"); new[] { factory(1, "red"), factory(1, "green"), factory(1, "blue") } .Distinct() .Single() .ShouldBeSameAs(blue); blue = metafactory()(1, "blue"); new[] { metafactory()(1, "red"), metafactory()(1, "green"), metafactory()(1, "blue") } .Distinct() .Single() .ShouldBeSameAs(blue); }