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


C# Container.TryResolve方法代码示例

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


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

示例1: TryResolveReturnsNullIfNotRegistered

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

            Assert.IsNull(container.TryResolve<IFoo>());
            Assert.IsNull(container.TryResolve<IFoo, string>("a1"));
            Assert.IsNull(container.TryResolve<IFoo, string, string>("a1", "a2"));
            Assert.IsNull(container.TryResolve<IFoo, string, string, string>("a1", "a2", "a3"));
            Assert.IsNull(container.TryResolve<IFoo, string, string, string, string>("a1", "a2", "a3", "a4"));
            Assert.IsNull(container.TryResolve<IFoo, string, string, string, string, string>("a1", "a2", "a3", "a4", "a5"));
            Assert.IsNull(container.TryResolve<IFoo, string, string, string, string, string, string>("a1", "a2", "a3", "a4", "a5", "a6"));
        }
开发者ID:RuhuiCheng,项目名称:TLFramework,代码行数:12,代码来源:ContainerFixture.cs

示例2: TryResolveServiceWithTypeObject

        public void TryResolveServiceWithTypeObject()
        {
            // Setup
            var container = new Container();
            container.Register<ServiceBase, ServiceWithNoConstructors>();

            // Execute
            object service;
            var result = container.TryResolve(typeof (ServiceBase), out service);

            // Assert
            Assert.IsTrue(result);
            Assert.IsTrue(service is ServiceWithNoConstructors);
        }
开发者ID:jsmunroe,项目名称:SimpleIoc,代码行数:14,代码来源:ContainerTest.cs

示例3: TryResolveUnregisteredService

        public void TryResolveUnregisteredService()
        {
            // Setup
            var container = new Container();

            // Execute
            ServiceBase service;
            var result = container.TryResolve(out service);

            // Assert
            Assert.IsFalse(result);
            Assert.IsNull(service);
        }
开发者ID:jsmunroe,项目名称:SimpleIoc,代码行数:13,代码来源:ContainerTest.cs

示例4: TryResolveServiceWithDependency

        public void TryResolveServiceWithDependency()
        {
            // Setup
            var container = new Container();
            container.Register<DependencyBase, Dependency1>();
            container.Register<ServiceBase, ServiceWithOneConstructor>();

            // Execute
            ServiceBase service;
            var result = container.TryResolve<ServiceBase>(out service);

            // Assert
            Assert.IsTrue(result);
            Assert.IsTrue(service is ServiceWithOneConstructor);
        }
开发者ID:jsmunroe,项目名称:SimpleIoc,代码行数:15,代码来源:ContainerTest.cs

示例5: TryResolveServiceWithName

        public void TryResolveServiceWithName()
        {
            // Setup
            var container = new Container();
            container.Register<ServiceBase, ServiceWithNoConstructors>("MyService");

            // Execute
            ServiceBase service;
            var result = container.TryResolve(out service);

            // Assert
            Assert.IsTrue(result);
            Assert.IsTrue(service is ServiceWithNoConstructors);
        }
开发者ID:jsmunroe,项目名称:SimpleIoc,代码行数:14,代码来源:ContainerTest.cs

示例6: TryResolveServiceThatIsConstructableWithoutRegistration

        public void TryResolveServiceThatIsConstructableWithoutRegistration()
        {
            // Setup
            var container = new Container();
            container.Register<DependencyBase, Dependency1>();

            // Execute
            ServiceWithOneConstructor service;
            var result = container.TryResolve<ServiceWithOneConstructor>(out service);

            // Assert
            Assert.IsTrue(result);
            Assert.IsTrue(service != null);
        }
开发者ID:jsmunroe,项目名称:SimpleIoc,代码行数:14,代码来源:ContainerTest.cs

示例7: TryResolveFuncServiceWithName

        public void TryResolveFuncServiceWithName()
        {
            // Setup
            var container = new Container();
            container.Register<ServiceBase>(() => new ServiceWithNoConstructors(), "MyService");

            // Execute
            object service;
            var result = container.TryResolve(typeof (ServiceBase), "MyService", out service);

            // Assert
            Assert.IsTrue(result);
            Assert.IsTrue(service is ServiceWithNoConstructors);
        }
开发者ID:jsmunroe,项目名称:SimpleIoc,代码行数:14,代码来源:ContainerTest.cs

示例8: TryResolveFuncService

        public void TryResolveFuncService()
        {
            // Setup
            var container = new Container();
            container.Register<ServiceBase>(() => new ServiceWithNoConstructors());

            // Execute
            ServiceBase service;
            var result = container.TryResolve<ServiceBase>(out service);

            // Assert
            Assert.IsTrue(result);
            Assert.IsInstanceOfType(service, typeof(ServiceWithNoConstructors));
        }
开发者ID:jsmunroe,项目名称:SimpleIoc,代码行数:14,代码来源:ContainerTest.cs

示例9: TryResolveComplexService

        public void TryResolveComplexService()
        {
            // Setup
            var container = new Container();
            container.Register<ComplexService1, ComplexService1>();
            container.Register<ComplexService2, ComplexService2>();
            container.Register<ComplexService3, ComplexService3>();
            container.Register<DependencyBase, Dependency1>();

            // Execute
            ComplexService1 service;
            var result = container.TryResolve<ComplexService1>(out service);

            // Assert
            Assert.IsTrue(result);
        }
开发者ID:jsmunroe,项目名称:SimpleIoc,代码行数:16,代码来源:ContainerTest.cs

示例10: TryResolve

        public void TryResolve()
        {
            // Setup
            var container = new Container();
            container.Register<ServiceBase, ServiceWithNoConstructors>();

            // Execute
            ServiceBase serviceBase;
            bool result = container.TryResolve(out serviceBase);

            // Assert
            Assert.IsTrue(result);
            Assert.IsInstanceOfType(serviceBase, typeof(ServiceWithNoConstructors));
        }
开发者ID:jsmunroe,项目名称:SimpleIoc,代码行数:14,代码来源:ContainerTest.cs


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