本文整理汇总了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();
}
}
示例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);
}
示例3: ConfigureServices
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.ConfigureMvc(options =>
{
options.AddXmlDataContractSerializerFormatter();
});
}
示例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",
}));
});
}
示例5: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.ConfigureMvc(options =>
{
options.Conventions.Add(new NameSpaceRoutingConvention());
});
// Add MVC services to the services container
services.AddMvc();
}
示例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());
});
}
示例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."));
});
}
示例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 => {
});
}
示例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>();
}
示例10: ConfigurationMVC
private static void ConfigurationMVC(IServiceCollection services)
{
services.ConfigureMvc(MVCOptionsConfigs);
services.AddMvc();
}