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


C# Container.LazyResolve方法代码示例

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


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

示例1: LazyResolveThrowsIfNotRegistered

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

            try
            {
                container.LazyResolve<IFoo>();
                Assert.Fail("Should have failed to resolve the lazy func");
            }
            catch (ResolutionException)
            {
            }

            try
            {
                container.LazyResolve<IFoo, string>();
                Assert.Fail("Should have failed to resolve the lazy func");
            }
            catch (ResolutionException)
            {
            }

            try
            {
                container.LazyResolve<IFoo, string, string>();
                Assert.Fail("Should have failed to resolve the lazy func");
            }
            catch (ResolutionException)
            {
            }

            try
            {
                container.LazyResolve<IFoo, string, string, string>();
                Assert.Fail("Should have failed to resolve the lazy func");
            }
            catch (ResolutionException)
            {
            }

            try
            {
                container.LazyResolve<IFoo, string, string, string, string>();
                Assert.Fail("Should have failed to resolve the lazy func");
            }
            catch (ResolutionException)
            {
            }

            try
            {
                container.LazyResolve<IFoo, string, string, string, string, string>();
                Assert.Fail("Should have failed to resolve the lazy func");
            }
            catch (ResolutionException)
            {
            }

            try
            {
                container.LazyResolve<IFoo, string, string, string, string, string, string>();
                Assert.Fail("Should have failed to resolve the lazy func");
            }
            catch (ResolutionException)
            {
            }
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:67,代码来源:ContainerFixture.cs

示例2: LazyResolveHonorsReuseScope

        public void LazyResolveHonorsReuseScope()
        {
            var container = new Container();
            container.Register<IFoo>(c => new Foo()).ReusedWithin(ReuseScope.Container);

            var func = container.LazyResolve<IFoo>();

            var f1 = func();
            var f2 = func();

            Assert.AreSame(f1, f2);
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:12,代码来源:ContainerFixture.cs

示例3: LazyResolveProvidedForRegisteredServices

        public void LazyResolveProvidedForRegisteredServices()
        {
            var container = new Container();
            container.Register<IFoo>(c => new Foo()).ReusedWithin(ReuseScope.Container);

            var func = container.LazyResolve<IFoo>();

            Assert.IsNotNull(func);
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:9,代码来源:ContainerFixture.cs

示例4: LazyResolveAllOverloads

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

            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.LazyResolve<Bar, string>()("a1");
            Assert.AreEqual("a1", b.Arg1);

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

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

            b = container.LazyResolve<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.LazyResolve<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.LazyResolve<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);
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:47,代码来源:ContainerFixture.cs


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