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


C# IServiceCollection.ConfigureMvc方法代码示例

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


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

示例1: ConfigureServices

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddCaching();
            services.AddSession();

            services.AddMvc();
            services.AddSingleton<PassThroughAttribute>();
            services.AddSingleton<UserNameService>();
            services.AddTransient<ITestService, TestService>();

            services.ConfigureMvc(options =>
            {
                options.Filters.Add(typeof(PassThroughAttribute), order: 17);
                options.AddXmlDataContractSerializerFormatter();
                options.Filters.Add(new FormatFilterAttribute());
            });

#if DNX451
            // Fully-qualify configuration path to avoid issues in functional tests. Just "config.json" would be fine
            // but Configuration uses CallContextServiceLocator.Locator.ServiceProvider to get IApplicationEnvironment.
            // Functional tests update that service but not in the static provider.
            var applicationEnvironment = services.BuildServiceProvider().GetRequiredService<IApplicationEnvironment>();
            var configurationPath = Path.Combine(applicationEnvironment.ApplicationBasePath, "config.json");

            // Set up configuration sources.
            var configuration = new Configuration()
                .AddJsonFile(configurationPath)
                .AddEnvironmentVariables();
            string diSystem;
            if (configuration.TryGet("DependencyInjection", out diSystem) &&
                diSystem.Equals("AutoFac", StringComparison.OrdinalIgnoreCase))
            {
                _autoFac = true;
                services.ConfigureRazorViewEngine(options =>
                {
                    var expander = new LanguageViewLocationExpander(
                        context => context.HttpContext.Request.Query["language"]);
                    options.ViewLocationExpanders.Insert(0, expander);
                });

                // Create the autofac container
                var builder = new ContainerBuilder();

                // Create the container and use the default application services as a fallback
                AutofacRegistration.Populate(
                    builder,
                    services);

                builder.RegisterModule<MonitoringModule>();

                var container = builder.Build();

                return container.Resolve<IServiceProvider>();
            }
            else
#endif
            {
                return services.BuildServiceProvider();
            }
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:60,代码来源:Startup.cs

示例2: ConfigureServices

        /// <summary>
        /// Configures the services to add to the ASP.NET MVC 6 Injection of Control (IoC) container. This method gets 
        /// called by the ASP.NET runtime. See:
        /// http://blogs.msdn.com/b/webdev/archive/2014/06/17/dependency-injection-in-asp-net-vnext.aspx
        /// </summary>
        /// <param name="services">The services collection or IoC container.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigureOptionsServices(services, this.Configuration);
            ConfigureCachingServices(services);

            // Add many MVC services to the services container.
            services.AddMvc();

            // Configure MVC routing. We store the route options for use by ConfigureSearchEngineOptimizationFilters.
            RouteOptions routeOptions = null;
            services.ConfigureRouting(
                x => 
                {
                    routeOptions = x;
                    ConfigureRouting(routeOptions);
                });

            // Configure all other MVC settings.
            services.ConfigureMvc(
                mvcOptions =>
                {
                    ConfigureCacheProfiles(mvcOptions.CacheProfiles);
                    ConfigureSearchEngineOptimizationFilters(mvcOptions.Filters, routeOptions);
                    ConfigureSecurityFilters(mvcOptions.Filters);
                    ConfigureContentSecurityPolicyFilters(mvcOptions.Filters);
                    ConfigureFormatters(mvcOptions);
                });

            ConfigureAntiforgeryServices(services);
            ConfigureCustomServices(services);
        }
开发者ID:vmoll,项目名称:ASP.NET-MVC-Boilerplate,代码行数:37,代码来源:Startup.cs

示例3: ConfigureServices

 // Set up application services
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc();
     services.ConfigureMvc(options =>
     {
         options.AddXmlDataContractSerializerFormatter();
     });
 }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:9,代码来源:Startup.cs

示例4: ConfigureServices

        // Set up application services
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.ConfigureMvc(options =>
            {
                options.CacheProfiles.Add(
                    "PublicCache30Sec", new CacheProfile
                    {
                        Duration = 30,
                        Location = ResponseCacheLocation.Any
                    });

                options.CacheProfiles.Add(
                    "PrivateCache30Sec", new CacheProfile
                    {
                        Duration = 30,
                        Location = ResponseCacheLocation.Client
                    });

                options.CacheProfiles.Add(
                    "NoCache", new CacheProfile
                    {
                        NoStore = true,
                        Duration = 0,
                        Location = ResponseCacheLocation.None
                    });

                options.CacheProfiles.Add(
                    "PublicCache30SecVaryByAcceptHeader", new CacheProfile
                    {
                        Duration = 30,
                        Location = ResponseCacheLocation.Any,
                        VaryByHeader = "Accept"
                    });
            });

            services.ConfigureMvc(options =>
            { 
                options.Filters.Add(new ResponseCacheFilter(new CacheProfile
                {
                    NoStore = true,
                    VaryByHeader = "TestDefault",
                }));
            });
        }
开发者ID:notami18,项目名称:Mvc,代码行数:46,代码来源:Startup.cs

示例5: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.ConfigureMvc(options =>
            {
                options.Conventions.Add(new NameSpaceRoutingConvention());
            });

            // Add MVC services to the services container
            services.AddMvc();
        }
开发者ID:Tragetaschen,项目名称:Entropy,代码行数:10,代码来源:Startup.cs

示例6: ConfigureServices

        // Set up application services
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.ConfigureMvc(options =>
            {
                options.Conventions.Add(new ApplicationDescription("Common Application Description"));
                options.Conventions.Add(new ControllerLicenseConvention());
                options.Conventions.Add(new FromHeaderConvention());
            });
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:12,代码来源:Startup.cs

示例7: ConfigureServices

        // Set up application services
        public void ConfigureServices(IServiceCollection services)
        {
            // Add MVC services to the services container
            services.AddMvc();

            services.AddSingleton<IActionDescriptorProvider, ActionDescriptorCreationCounter>();

            services.ConfigureMvc(options =>
            {
                options.Conventions.Add(new ApplicationDescription("This is a basic website."));
            });

        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:14,代码来源:Startup.cs

示例8: ConfigureServices

		public void ConfigureServices(IServiceCollection services)
		{
			services.AddSingleton<EnglishGreeter>();
			services.AddSingleton<RussianGreeter>();
			services.AddScoped<IGreeter>(factory => {
				var c = factory.GetRequiredService<IHttpContextAccessor>();
				HttpContext context = c.HttpContext;
				var isRu = context.Request.Path.StartsWithSegments(new PathString("/ru"));
				if (isRu)
					return factory.GetRequiredService<RussianGreeter>();
				else
					return factory.GetRequiredService<EnglishGreeter>();
			});
			services.AddMvc();
			services.ConfigureMvc(config => {
			});
		}
开发者ID:vcsjones,项目名称:Presentations,代码行数:17,代码来源:Startup.cs

示例9: ConfigureServices

        /// <summary>
        /// Configures the services to add to the ASP.NET MVC 6 Injection of Control (IoC) container. This method gets 
        /// called by the ASP.NET runtime. See:
        /// http://blogs.msdn.com/b/webdev/archive/2014/06/17/dependency-injection-in-asp-net-vnext.aspx
        /// </summary>
        /// <param name="services">The services collection or IoC container.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            // Add IOptions<AppSettings> to the services container.
            services.Configure<AppSettings>(this.Configuration.GetConfigurationSection("AppSettings"));

            // Add many MVC services to the services container.
            services.AddMvc();

            RouteOptions routeOptions = null;
            services.ConfigureRouting(x => { routeOptions = x; ConfigureRouting(routeOptions); });

            services.ConfigureMvc(mvcOptions =>
            {
                ConfigureAntiforgeryTokens(mvcOptions.AntiForgeryOptions);
                ConfigureCacheProfiles(mvcOptions.CacheProfiles);
                ConfigureSearchEngineOptimizationFilters(mvcOptions.Filters, routeOptions);
                ConfigureSecurityFilters(mvcOptions.Filters);
                ConfigureContentSecurityPolicyFilters(mvcOptions.Filters);
                ConfigureFormatters(mvcOptions);
            });

#if DNX451
            services.AddScoped<IFeedService, FeedService>();
#endif
            services.AddSingleton<ILoggingService, LoggingService>();
            services.AddScoped<IOpenSearchService, OpenSearchService>();
            services.AddScoped<IRobotsService, RobotsService>();
            services.AddScoped<ISitemapService, SitemapService>();
            services.AddScoped<ISitemapPingerService, SitemapPingerService>();

            // Add your own custom services here e.g.

            // Singleton - Only one instance is ever created and returned.
            // services.AddSingleton<IDatabaseService, DatabaseService>();

            // Scoped - A new instance is created and returned for each request/response cycle.
            // services.AddScoped<IDatabaseService, DatabaseService>();

            // Transient - A new instance is created and returned each time.
            // services.AddTransient<IDatabaseService, DatabaseService>();
        }
开发者ID:andyshao,项目名称:ASP.NET-MVC-Boilerplate,代码行数:47,代码来源:Startup.cs

示例10: ConfigurationMVC

 private static void ConfigurationMVC(IServiceCollection services)
 {
     services.ConfigureMvc(MVCOptionsConfigs);
     services.AddMvc();
 }
开发者ID:trungdd2811,项目名称:MongoMVC6,代码行数:5,代码来源:Startup.MVCConfigs.cs


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