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


C# DefaultServices.GetService方法代码示例

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


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

示例1: GetService_CachesResultFromDependencyInjectionContainer

        public void GetService_CachesResultFromDependencyInjectionContainer()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            var mockDependencyResolver = new Mock<IDependencyResolver>();
            config.DependencyResolver = mockDependencyResolver.Object;

            // Act
            defaultServices.GetService(typeof(IActionValueBinder));
            defaultServices.GetService(typeof(IActionValueBinder));

            // Assert
            mockDependencyResolver.Verify(dr => dr.GetService(typeof(IActionValueBinder)), Times.Once());
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:15,代码来源:DefaultServicesTests.cs

示例2: Constructor_DefaultServicesInContainer

        public void Constructor_DefaultServicesInContainer()
        {
            // Arrange
            var config = new HttpConfiguration();

            // Act
            var defaultServices = new DefaultServices(config);

            // Assert
            Assert.Null(defaultServices.GetService(typeof(IDocumentationProvider)));
            Assert.Null(defaultServices.GetService(typeof(ITraceWriter)));

            Assert.IsType<DefaultActionValueBinder>(defaultServices.GetService(typeof(IActionValueBinder)));
            Assert.IsType<ApiExplorer>(defaultServices.GetService(typeof(IApiExplorer)));
            Assert.IsType<DefaultAssembliesResolver>(defaultServices.GetService(typeof(IAssembliesResolver)));
            Assert.IsType<DefaultBodyModelValidator>(defaultServices.GetService(typeof(IBodyModelValidator)));
            Assert.IsType<DefaultContentNegotiator>(defaultServices.GetService(typeof(IContentNegotiator)));
            Assert.IsType<ApiControllerActionInvoker>(defaultServices.GetService(typeof(IHttpActionInvoker)));
            Assert.IsType<ApiControllerActionSelector>(defaultServices.GetService(typeof(IHttpActionSelector)));
            Assert.IsType<DefaultHttpControllerActivator>(defaultServices.GetService(typeof(IHttpControllerActivator)));
            Assert.IsType<DefaultHttpControllerSelector>(defaultServices.GetService(typeof(IHttpControllerSelector)));
            Assert.IsType<DefaultHttpControllerTypeResolver>(defaultServices.GetService(typeof(IHttpControllerTypeResolver)));
            Assert.IsType<TraceManager>(defaultServices.GetService(typeof(ITraceManager)));
            Assert.IsType<DataAnnotationsModelMetadataProvider>(defaultServices.GetService(typeof(ModelMetadataProvider)));
            Assert.IsType<ModelValidatorCache>(defaultServices.GetService(typeof(IModelValidatorCache)));

            object[] filterProviders = defaultServices.GetServices(typeof(IFilterProvider)).ToArray();
            Assert.Equal(2, filterProviders.Length);
            Assert.IsType<ConfigurationFilterProvider>(filterProviders[0]);
            Assert.IsType<ActionDescriptorFilterProvider>(filterProviders[1]);

            object[] modelBinderProviders = defaultServices.GetServices(typeof(ModelBinderProvider)).ToArray();
            Assert.Equal(8, modelBinderProviders.Length);
            Assert.IsType<TypeConverterModelBinderProvider>(modelBinderProviders[0]);
            Assert.IsType<TypeMatchModelBinderProvider>(modelBinderProviders[1]);
            Assert.IsType<KeyValuePairModelBinderProvider>(modelBinderProviders[2]);
            Assert.IsType<ComplexModelDtoModelBinderProvider>(modelBinderProviders[3]);
            Assert.IsType<ArrayModelBinderProvider>(modelBinderProviders[4]);
            Assert.IsType<DictionaryModelBinderProvider>(modelBinderProviders[5]);
            Assert.IsType<CollectionModelBinderProvider>(modelBinderProviders[6]);
            Assert.IsType<MutableObjectModelBinderProvider>(modelBinderProviders[7]);

            object[] validatorProviders = defaultServices.GetServices(typeof(ModelValidatorProvider)).ToArray();
            Assert.Equal(2, validatorProviders.Length);
            Assert.IsType<DataAnnotationsModelValidatorProvider>(validatorProviders[0]);
            Assert.IsType<DataMemberModelValidatorProvider>(validatorProviders[1]);

            object[] valueProviderFactories = defaultServices.GetServices(typeof(ValueProviderFactory)).ToArray();
            Assert.Equal(2, valueProviderFactories.Length);
            Assert.IsType<QueryStringValueProviderFactory>(valueProviderFactories[0]);
            Assert.IsType<RouteDataValueProviderFactory>(valueProviderFactories[1]);
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:52,代码来源:DefaultServicesTests.cs

示例3: GetService_PrefersServiceInDependencyInjectionContainer

        public void GetService_PrefersServiceInDependencyInjectionContainer()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider = new Mock<IActionValueBinder>().Object;
            var mockDependencyResolver = new Mock<IDependencyResolver>();
            mockDependencyResolver.Setup(dr => dr.GetService(typeof(IActionValueBinder))).Returns(filterProvider);
            config.DependencyResolver = mockDependencyResolver.Object;

            // Act
            object service = defaultServices.GetService(typeof(IActionValueBinder));

            // Assert
            Assert.Same(filterProvider, service);
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:16,代码来源:DefaultServicesTests.cs

示例4: GetService_ReturnsNullWhenServiceListEmpty

        public void GetService_ReturnsNullWhenServiceListEmpty()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            defaultServices.Clear(typeof(IActionValueBinder));

            // Act
            object service = defaultServices.GetService(typeof(IActionValueBinder));

            // Assert
            Assert.Null(service);
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:13,代码来源:DefaultServicesTests.cs

示例5: GetService_GuardClauses

        public void GetService_GuardClauses()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            Assert.ThrowsArgumentNull(() => defaultServices.GetService(serviceType: null), "serviceType");
            Assert.ThrowsArgument(
                () => defaultServices.GetService(typeof(object)),
                "serviceType",
                "The service type Object is not supported.");
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:13,代码来源:DefaultServicesTests.cs

示例6: Class_IsDefaultIAssembliesResolver

        public void Class_IsDefaultIAssembliesResolver()
        {
            var serviceResolver = new DefaultServices(new HttpConfiguration());

            Assert.IsType<DefaultAssembliesResolver>(serviceResolver.GetService(typeof(IAssembliesResolver)));
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:6,代码来源:DefaultAssembliesResolverTest.cs

示例7: GetService_ReturnsFirstServiceInList

        public void GetService_ReturnsFirstServiceInList()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));

            // Act
            object service = defaultServices.GetService(typeof(IFilterProvider));

            // Assert
            Assert.Same(servicesBefore.First(), service);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:13,代码来源:DefaultServicesTests.cs


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