コード例 #1
0
        private void Test_BindPerMultiKey <TService, TImplementation>() where TImplementation : TService
        {
            var k = new StandardKernel();

            k.BindPerMultiKey <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");

            factory(1, "blue").ShouldBeSameAs(blue);
            new[] { factory(1, "red"), factory(1, "green"), factory(1, "blue") }
            .Distinct()
            .Count()
            .ShouldBe(3);

            blue = metafactory()(1, "blue");
            metafactory()(1, "blue").ShouldBeSameAs(blue);
            new[] { metafactory()(1, "red"), metafactory()(1, "green"), metafactory()(1, "blue") }
            .Distinct()
            .Count()
            .ShouldBe(3);
        }