当前位置: 首页>>代码示例>>C#>>正文


C# Container.ResolveNamed方法代码示例

本文整理汇总了C#中Container.ResolveNamed方法的典型用法代码示例。如果您正苦于以下问题:C# Container.ResolveNamed方法的具体用法?C# Container.ResolveNamed怎么用?C# Container.ResolveNamed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Container的用法示例。


在下文中一共展示了Container.ResolveNamed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ThrowsIfCannotResolveNamed

        public void ThrowsIfCannotResolveNamed()
        {
            var container = new Container();

            try
            {
                var foo = container.ResolveNamed<IFoo>("foo");
                Assert.Fail("Should have thrown ResolutionException");
            }
            catch (ResolutionException re)
            {
                Assert.IsTrue(re.Message.IndexOf("foo") != -1);
            }
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:14,代码来源:ContainerFixture.cs

示例2: RegistersAllOverloads

        public void RegistersAllOverloads()
        {
            var container = new Container();

            container.Register<Bar>("bar", c => new Bar());
            container.Register<Bar, string>("bar", (c, s) => new Bar(s));
            container.Register<Bar, string, string>("bar", (c, s1, s2) => new Bar(s1, s2));
            container.Register<Bar, string, string, string>("bar", (c, s1, s2, s3) => new Bar(s1, s2, s3));
            container.Register<Bar, string, string, string, string>("bar", (c, s1, s2, s3, s4) => new Bar(s1, s2, s3, s4));
            container.Register<Bar, string, string, string, string, string>("bar", (c, s1, s2, s3, s4, s5) => new Bar(s1, s2, s3, s4, s5));
            container.Register<Bar, string, string, string, string, string, string>("bar", (c, s1, s2, s3, s4, s5, s6) => new Bar(s1, s2, s3, s4, s5, s6));

            container.Register<Bar>(c => new Bar());
            container.Register<Bar, string>((c, s) => new Bar(s));
            container.Register<Bar, string, string>((c, s1, s2) => new Bar(s1, s2));
            container.Register<Bar, string, string, string>((c, s1, s2, s3) => new Bar(s1, s2, s3));
            container.Register<Bar, string, string, string, string>((c, s1, s2, s3, s4) => new Bar(s1, s2, s3, s4));
            container.Register<Bar, string, string, string, string, string>((c, s1, s2, s3, s4, s5) => new Bar(s1, s2, s3, s4, s5));
            container.Register<Bar, string, string, string, string, string, string>((c, s1, s2, s3, s4, s5, s6) => new Bar(s1, s2, s3, s4, s5, s6));

            Assert.IsNotNull(container.Resolve<Bar>());

            var b = container.Resolve<Bar, string>("a1");
            Assert.AreEqual("a1", b.Arg1);

            b = container.Resolve<Bar, string, string>("a1", "a2");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);

            b = container.Resolve<Bar, string, string, string>("a1", "a2", "a3");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);
            Assert.AreEqual("a3", b.Arg3);

            b = container.Resolve<Bar, string, string, string, string>("a1", "a2", "a3", "a4");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);
            Assert.AreEqual("a3", b.Arg3);
            Assert.AreEqual("a4", b.Arg4);

            b = container.Resolve<Bar, string, string, string, string, string>("a1", "a2", "a3", "a4", "a5");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);
            Assert.AreEqual("a3", b.Arg3);
            Assert.AreEqual("a4", b.Arg4);
            Assert.AreEqual("a5", b.Arg5);

            b = container.Resolve<Bar, string, string, string, string, string, string>("a1", "a2", "a3", "a4", "a5", "a6");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);
            Assert.AreEqual("a3", b.Arg3);
            Assert.AreEqual("a4", b.Arg4);
            Assert.AreEqual("a5", b.Arg5);
            Assert.AreEqual("a6", b.Arg6);

            Assert.IsNotNull(container.ResolveNamed<Bar>("bar"));

            b = container.ResolveNamed<Bar, string>("bar", "a1");
            Assert.AreEqual("a1", b.Arg1);

            b = container.ResolveNamed<Bar, string, string>("bar", "a1", "a2");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);

            b = container.ResolveNamed<Bar, string, string, string>("bar", "a1", "a2", "a3");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);
            Assert.AreEqual("a3", b.Arg3);

            b = container.ResolveNamed<Bar, string, string, string, string>("bar", "a1", "a2", "a3", "a4");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);
            Assert.AreEqual("a3", b.Arg3);
            Assert.AreEqual("a4", b.Arg4);

            b = container.ResolveNamed<Bar, string, string, string, string, string>("bar", "a1", "a2", "a3", "a4", "a5");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);
            Assert.AreEqual("a3", b.Arg3);
            Assert.AreEqual("a4", b.Arg4);
            Assert.AreEqual("a5", b.Arg5);

            b = container.ResolveNamed<Bar, string, string, string, string, string, string>("bar", "a1", "a2", "a3", "a4", "a5", "a6");
            Assert.AreEqual("a1", b.Arg1);
            Assert.AreEqual("a2", b.Arg2);
            Assert.AreEqual("a3", b.Arg3);
            Assert.AreEqual("a4", b.Arg4);
            Assert.AreEqual("a5", b.Arg5);
            Assert.AreEqual("a6", b.Arg6);
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:90,代码来源:ContainerFixture.cs

示例3: RegistersNamedInstances

        public void RegistersNamedInstances()
        {
            var container = new Container();
            container.Register<IFoo>("foo", c => new Foo());
            container.Register<IFoo>("foo2", c => new Foo2());

            var foo = container.ResolveNamed<IFoo>("foo");
            var foo2 = container.ResolveNamed<IFoo>("foo2");

            Assert.AreNotSame(foo, foo2);
            Assert.IsTrue(foo is IFoo);
            Assert.IsTrue(foo2 is IFoo);
            Assert.IsTrue(foo is Foo);
            Assert.IsTrue(foo2 is Foo2);
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:15,代码来源:ContainerFixture.cs

示例4: RegisterOrderForNamedDoesNotMatter

        public void RegisterOrderForNamedDoesNotMatter()
        {
            var container = new Container();
            container.Register<IFoo>(c => new Foo());
            container.Register<IFoo>("foo", c => new Foo("foo"));

            var foo = container.Resolve<IFoo>();
            var foo2 = container.ResolveNamed<IFoo>("foo");

            Assert.IsNotNull(foo);
            Assert.IsNotNull(foo2);

            Assert.AreEqual("foo", ((Foo)foo2).Value);
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:14,代码来源:ContainerFixture.cs


注:本文中的Container.ResolveNamed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。