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


C# ServiceCollection.AddMvc方法代码示例

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


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

示例1: MultiRegistrationServiceTypes_AreRegistered_MultipleTimes

        public void MultiRegistrationServiceTypes_AreRegistered_MultipleTimes()
        {
            // Arrange
            var services = new ServiceCollection();

            // Register a mock implementation of each service, AddMvcServices should add another implemenetation.
            foreach (var serviceType in MutliRegistrationServiceTypes)
            {
                var mockType = typeof(Mock<>).MakeGenericType(serviceType.Key);
                services.Add(ServiceDescriptor.Transient(serviceType.Key, mockType));
            }

            // Act
            services.AddMvc();

            // Assert
            foreach (var serviceType in MutliRegistrationServiceTypes)
            {
                AssertServiceCountEquals(services, serviceType.Key, serviceType.Value.Length + 1);

                foreach (var implementationType in serviceType.Value)
                {
                    AssertContainsSingle(services, serviceType.Key, implementationType);
                }
            }
        }
开发者ID:phinq19,项目名称:git_example,代码行数:26,代码来源:MvcServiceCollectionExtensionsTest.cs

示例2: Resolve_AddTypedRoutingShouldAddExpressionRouteHelper

        public void Resolve_AddTypedRoutingShouldAddExpressionRouteHelper()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddMvc().AddTypedRouting();

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var expressionRouteHelper = serviceProvider.GetRequiredService<IExpressionRouteHelper>();
            Assert.IsAssignableFrom<ExpressionRouteHelper>(expressionRouteHelper);
        }
开发者ID:ivaylokenov,项目名称:AspNet.Mvc.TypedRouting,代码行数:11,代码来源:ExpressionRouteHelperTest.cs

示例3: ShoppingCartControllerTest

        public ShoppingCartControllerTest()
        {
            var services = new ServiceCollection();

            services.AddEntityFramework()
                      .AddInMemoryDatabase()
                      .AddDbContext<MusicStoreContext>(options => options.UseInMemoryDatabase());

            services.AddMvc();

            _serviceProvider = services.BuildServiceProvider();
        }
开发者ID:leloulight,项目名称:MusicStore,代码行数:12,代码来源:ShoppingCartControllerTest.cs

示例4: GetServiceProvider

		public static IServiceProvider GetServiceProvider()
		{
			var services = new ServiceCollection();
			services.AddMvc();
			services.AddEntityFramework()
				.AddInMemoryDatabase()
				.AddDbContext<ChatLeIdentityDbContext>(options => options.UseInMemoryDatabase());
			services.AddInstance<ILoggerFactory>(new LoggerFactory());
			services.AddIdentity<ChatLeUser, IdentityRole>();
			services.AddChatLe();
			return services.BuildServiceProvider();
		}
开发者ID:IEvangelist,项目名称:chatle,代码行数:12,代码来源:TestUtils.cs

示例5: ShoppingCartControllerTest

        public ShoppingCartControllerTest()
        {
            var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();

            var services = new ServiceCollection();
            services
                .AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>()
                .AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));

            services.AddMvc();

            _serviceProvider = services.BuildServiceProvider();
        }
开发者ID:Corays,项目名称:MusicStore,代码行数:13,代码来源:ShoppingCartControllerTest.cs

示例6: CreateNode

        public static Node CreateNode(out IServiceProvider provider)
        {
            IServiceCollection sc = new ServiceCollection();
            sc.AddLogging();
            sc.AddInMemoryRPC();
            sc.AddRaft(p => {
                p.UseLogging = true;
                p.FailureTolerance = -1;
            });
            sc.AddMvc();
            sc.Configure<RaftOptions>(p => { });
            provider = sc.BuildServiceProvider();

            var loggerFactory = provider.GetService<ILoggerFactory>();
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();
            
            return provider.GetService<Node>();
        }
开发者ID:RossMerr,项目名称:Caudex.Rafting,代码行数:20,代码来源:NodeBuilder.cs

示例7: SingleRegistrationServiceTypes_AreNotRegistered_MultipleTimes

        public void SingleRegistrationServiceTypes_AreNotRegistered_MultipleTimes()
        {
            // Arrange
            var services = new ServiceCollection();

            // Register a mock implementation of each service, AddMvcServices should not replace it.
            foreach (var serviceType in SingleRegistrationServiceTypes)
            {
                var mockType = typeof(Mock<>).MakeGenericType(serviceType);
                services.Add(ServiceDescriptor.Transient(serviceType, mockType));
            }

            // Act
            services.AddMvc();

            // Assert
            foreach (var singleRegistrationType in SingleRegistrationServiceTypes)
            {
                AssertServiceCountEquals(services, singleRegistrationType, 1);
            }
        }
开发者ID:phinq19,项目名称:git_example,代码行数:21,代码来源:MvcServiceCollectionExtensionsTest.cs

示例8: InitializeServices

        private static void InitializeServices(HttpContext httpContext, Action<MvcOptions> updateOptions = null)
        {
            var serviceCollection = new ServiceCollection();
            serviceCollection.AddMvc();

            httpContext.RequestServices = serviceCollection.BuildServiceProvider();

            var actionContext = new ActionContext(httpContext, new RouteData(), new ControllerActionDescriptor());

            var actionContextAccessor =
                httpContext.RequestServices.GetRequiredService<IActionContextAccessor>();
            actionContextAccessor.ActionContext = actionContext;

            var options = new TestMvcOptions().Value;
            if (updateOptions != null)
            {
                updateOptions(options);
            }

            var actionBindingContextAccessor =
                httpContext.RequestServices.GetRequiredService<IActionBindingContextAccessor>();
            actionBindingContextAccessor.ActionBindingContext = GetActionBindingContext(options, actionContext);
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:23,代码来源:ModelBindingTestHelper.cs

示例9: GetHttpContext

        private static HttpContext GetHttpContext(
            Action<HttpRequest> updateRequest = null,
            Action<MvcOptions> updateOptions = null)
        {
            var httpContext = new DefaultHttpContext();

            if (updateRequest != null)
            {
                updateRequest(httpContext.Request);
            }

            var serviceCollection = new ServiceCollection();
            serviceCollection.AddMvc();
            serviceCollection.AddTransient<ILoggerFactory, LoggerFactory>();

            if (updateOptions != null)
            {
                serviceCollection.Configure(updateOptions);
            }

            httpContext.RequestServices = serviceCollection.BuildServiceProvider();
            return httpContext;
        }
开发者ID:phinq19,项目名称:git_example,代码行数:23,代码来源:ModelBindingTestHelper.cs

示例10: AddMvcServicesTwice_DoesNotAddDuplicates

        public void AddMvcServicesTwice_DoesNotAddDuplicates()
        {
            // Arrange
            var services = new ServiceCollection();

            // Act
            services.AddMvc();
            services.AddMvc();

            // Assert
            var singleRegistrationServiceTypes = SingleRegistrationServiceTypes;
            foreach (var service in services)
            {
                if (singleRegistrationServiceTypes.Contains(service.ServiceType))
                {
                    // 'single-registration' services should only have one implementation registered.
                    AssertServiceCountEquals(services, service.ServiceType, 1);
                }
                else if (service.ImplementationType != null && !service.ImplementationType.GetTypeInfo().Assembly.FullName.Contains("Mvc"))
                {
                    // Ignore types that don't come from MVC
                }
                else
                {
                    // 'multi-registration' services should only have one *instance* of each implementation registered.
                    AssertContainsSingle(services, service.ServiceType, service.ImplementationType);
                }
            }
        }
开发者ID:phinq19,项目名称:git_example,代码行数:29,代码来源:MvcServiceCollectionExtensionsTest.cs

示例11: AddMvc_AddsAssemblyPartsForFrameworkTagHelpers

        public void AddMvc_AddsAssemblyPartsForFrameworkTagHelpers()
        {
            // Arrange
            var mvcRazorAssembly = typeof(UrlResolutionTagHelper).GetTypeInfo().Assembly;
            var mvcTagHelpersAssembly = typeof(InputTagHelper).GetTypeInfo().Assembly;
            var services = new ServiceCollection();
            var providers = new IApplicationFeatureProvider[]
            {
                new ControllerFeatureProvider(),
                new ViewComponentFeatureProvider()
            };

            // Act
            services.AddMvc();

            // Assert
            var descriptor = Assert.Single(services, d => d.ServiceType == typeof(ApplicationPartManager));
            Assert.Equal(ServiceLifetime.Singleton, descriptor.Lifetime);
            Assert.NotNull(descriptor.ImplementationInstance);
            var manager = Assert.IsType<ApplicationPartManager>(descriptor.ImplementationInstance);

            Assert.Equal(2, manager.ApplicationParts.Count);
            Assert.Single(manager.ApplicationParts.OfType<AssemblyPart>(), p => p.Assembly == mvcRazorAssembly);
            Assert.Single(manager.ApplicationParts.OfType<AssemblyPart>(), p => p.Assembly == mvcTagHelpersAssembly);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:25,代码来源:MvcServiceCollectionExtensionsTest.cs

示例12: AddMvcTwice_DoesNotAddApplicationFeatureProvidersTwice

        public void AddMvcTwice_DoesNotAddApplicationFeatureProvidersTwice()
        {
            // Arrange
            var services = new ServiceCollection();
            var providers = new IApplicationFeatureProvider[]
            {
                new ControllerFeatureProvider(),
                new ViewComponentFeatureProvider()
            };

            // Act
            services.AddMvc();
            services.AddMvc();

            // Assert
            var descriptor = Assert.Single(services, d => d.ServiceType == typeof(ApplicationPartManager));
            Assert.Equal(ServiceLifetime.Singleton, descriptor.Lifetime);
            Assert.NotNull(descriptor.ImplementationInstance);
            var manager = Assert.IsType<ApplicationPartManager>(descriptor.ImplementationInstance);

            Assert.Collection(manager.FeatureProviders,
                feature => Assert.IsType<ControllerFeatureProvider>(feature),
                feature => Assert.IsType<ViewComponentFeatureProvider>(feature),
                feature => Assert.IsType<TagHelperFeatureProvider>(feature),
                feature => Assert.IsType<MetadataReferenceFeatureProvider>(feature));
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:26,代码来源:MvcServiceCollectionExtensionsTest.cs

示例13: AddMvcCore_ReusesExistingApplicationPartManagerInstance_IfFoundOnServiceCollection

        public void AddMvcCore_ReusesExistingApplicationPartManagerInstance_IfFoundOnServiceCollection()
        {
            // Arrange
            var services = new ServiceCollection();
            var manager = new ApplicationPartManager();
            services.AddSingleton(manager);

            // Act
            services.AddMvc();

            // Assert
            var descriptor = Assert.Single(services, d => d.ServiceType == typeof(ApplicationPartManager));
            Assert.Same(manager, descriptor.ImplementationInstance);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:14,代码来源:MvcServiceCollectionExtensionsTest.cs


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