本文整理汇总了C#中IServiceCollection.AddRouting方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddRouting方法的具体用法?C# IServiceCollection.AddRouting怎么用?C# IServiceCollection.AddRouting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddRouting方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ISiteMapNodeService, NavigationTreeSiteMapNodeService>();
services.AddCloudscribeNavigation(Configuration.GetSection("NavigationOptions"));
services.AddRouting(options =>
{
options.LowercaseUrls = true;
});
services.Configure<MvcOptions>(options =>
{
// options.InputFormatters.Add(new Xm)
options.CacheProfiles.Add("SiteMapCacheProfile",
new CacheProfile
{
Duration = 100
});
});
services.AddMvc()
.AddRazorOptions(options =>
{
// if you download the cloudscribe.Web.Navigation Views and put them in your views folder
// then you don't need this line and can customize the views (recommended)
// you can find them here:
// https://github.com/joeaudette/cloudscribe.Web.Navigation/tree/master/src/cloudscribe.Web.Navigation/Views
options.AddEmbeddedViewsForNavigation();
});
}
示例2: ConfigureServices
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddRouting();
SprayChronicleServer.ContainerBuilder().Populate(services);
return SprayChronicleServer.Container().Resolve<IServiceProvider>();
}
示例3: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices( IServiceCollection services )
{
string connectionString = "Data Source=.;Initial Catalog=AspNetCoreImage;Integrated Security=SSPI;App=AspNetCoreImages;";
services.AddRouting();
services.AddMvc();
services.AddDbContext<UnitOfWork>( options => options.UseSqlServer( connectionString ) );
services.AddScoped<IImageRepository, ImageRepository>();
}
示例4: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddRouting(routeOptions =>
{
routeOptions.ConstraintMap.Add("IsbnDigitScheme10", typeof(IsbnDigitScheme10Constraint));
routeOptions.ConstraintMap.Add("IsbnDigitScheme13", typeof(IsbnDigitScheme13Constraint));
});
// Add MVC services to the services container
services.AddMvc();
}
示例5: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddRouting();
services.AddLogging();
services.AddAuthorization();
services.AddInstance<IControllerActivator>(new SimpleInjectorControllerActivator(container));
services.AddInstance<IViewComponentInvokerFactory>(new SimpleInjectorViewComponentInvokerFactory(container));
}
示例6: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddRouting();
services.AddMvc();
services.AddSingleton<IRequestIdFactory, RequestIdFactory>();
services.AddScoped<IRequestId, RequestId>();
services.Configure<RequestCultureOptions>(options =>
{
options.DefaultCulture = new CultureInfo(Configuration["culture"] ?? "en-GB");
});
}
示例7: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
ConfigureCachingServices(services);
RouteOptions routeOptions = null;
services.AddRouting(
x =>
{
routeOptions = x;
ConfigureRouting(x);
});
IMvcBuilder mvcBuilder = services.AddMvc(
mvcOptions =>
{
ConfigureSecurityFilters(this.hostingEnvironment, mvcOptions.Filters);
});
ConfigureAntiforgeryServices(services, this.hostingEnvironment);
}
示例8: ConfigureServices
public void ConfigureServices(IServiceCollection services) {
services.AddOptions()
.Configure<LoggingOptions>(Program.Configuration.GetSection("logging"))
.Configure<LifetimeOptions>(Program.Configuration.GetSection("lifetime"))
.Configure<SecurityOptions>(Program.Configuration.GetSection("security"))
.Configure<ROptions>(Program.Configuration.GetSection("R"));
services.AddSingleton<IFileSystem>(new FileSystem())
.AddSingleton<LifetimeManager>()
.AddSingleton<SecurityManager>()
.AddSingleton<InterpreterManager>()
.AddSingleton<SessionManager>()
.AddSingleton<UserProfileManager>();
services.AddAuthorization(options => options.AddPolicy(
Policies.RUser,
policy => policy.RequireClaim(Claims.RUser)));
services.AddRouting();
services.AddMvc();
}
示例9: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseInMemoryDatabase(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddRouting();
services.AddMvc();
services.Configure<RouteOptions>(options =>
options.ConstraintMap.Add("host", typeof(HostRouteConstraint)));
services.AddSingleton<IConfiguration>(sp => { return Configuration; });
// Add application services.
services.AddScoped<ILogConfigurationRepository, LogConfigurationRepository>();
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
示例10: 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)
{
ConfigureAntiforgeryServices(services, this.hostingEnvironment);
ConfigureCachingServices(services);
ConfigureOptionsServices(services, this.configuration);
// Configure MVC routing. We store the route options for use by ConfigureSearchEngineOptimizationFilters.
RouteOptions routeOptions = null;
IMvcBuilder mvcBuilder = services
.AddRouting(
x =>
{
routeOptions = x;
ConfigureRouting(x);
})
// Add useful interface for accessing the ActionContext outside a controller.
.AddSingleton<IActionContextAccessor, ActionContextAccessor>()
// Add useful interface for accessing the HttpContext outside a controller.
.AddSingleton<IHttpContextAccessor, HttpContextAccessor>()
// Add useful interface for accessing the IUrlHelper outside a controller.
.AddScoped<IUrlHelper>(x => x
.GetRequiredService<IUrlHelperFactory>()
.GetUrlHelper(x.GetRequiredService<IActionContextAccessor>().ActionContext))
// Add many MVC services to the services container.
.AddMvc(
mvcOptions =>
{
ConfigureCacheProfiles(mvcOptions.CacheProfiles, this.configuration);
ConfigureSearchEngineOptimizationFilters(mvcOptions.Filters, routeOptions);
ConfigureSecurityFilters(this.hostingEnvironment, mvcOptions.Filters);
ConfigureContentSecurityPolicyFilters(this.hostingEnvironment, mvcOptions.Filters);
});
ConfigureFormatters(mvcBuilder);
ConfigureCustomServices(services);
}
示例11: ConfigureDefaultServices
private static void ConfigureDefaultServices(IServiceCollection services)
{
services.AddOptions();
services.AddRouting();
}
示例12: ConfigureDefaultServices
private static void ConfigureDefaultServices(IServiceCollection services)
{
services.AddOptions();
services.AddDataProtection();
services.AddRouting();
services.AddCors();
services.AddAuthorization();
services.AddWebEncoders();
services.Configure<RouteOptions>(
routeOptions => routeOptions.ConstraintMap.Add("exists", typeof(KnownRouteValueConstraint)));
}
示例13: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// since we are protecting some data such as social auth secrets in the db
// we need our data protection keys to be located on disk where we can find them if
// we need to move to different hosting, without those key on the new host it would not be possible to decrypt
// but it is perhaps a little risky storing these keys below the appRoot folder
// for your own production envrionments store them outside of that if possible
string pathToCryptoKeys = Path.Combine(environment.ContentRootPath, "dp_keys");
services.AddDataProtection()
.PersistKeysToFileSystem(new System.IO.DirectoryInfo(pathToCryptoKeys));
// waiting for RTM compatible glimpse
//bool enableGlimpse = Configuration.GetValue("DiagnosticOptions:EnableGlimpse", false);
//if (enableGlimpse)
//{
// services.AddGlimpse();
//}
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedProto;
});
services.AddMemoryCache();
// we currently only use session for alerts, so we can fire an alert on the next request
// if session is disabled this feature fails quietly with no errors
services.AddSession();
// add authorization policies
ConfigureAuthPolicy(services);
services.AddOptions();
/* optional and only needed if you are using cloudscribe Logging */
//services.AddCloudscribeLoggingNoDbStorage(Configuration);
services.AddCloudscribeLogging();
/* these are optional and only needed if using cloudscribe Setup */
//services.Configure<SetupOptions>(Configuration.GetSection("SetupOptions"));
//services.AddScoped<SetupManager, SetupManager>();
//services.AddScoped<IVersionProvider, SetupVersionProvider>();
//services.AddScoped<IVersionProvider, CloudscribeLoggingVersionProvider>();
/* end cloudscribe Setup */
//services.AddSingleton<IThemeListBuilder, SharedThemeListBuilder>();
services.AddCloudscribeCore(Configuration);
services.Configure<GlobalResourceOptions>(Configuration.GetSection("GlobalResourceOptions"));
services.AddSingleton<IStringLocalizerFactory, GlobalResourceManagerStringLocalizerFactory>();
services.AddLocalization(options => options.ResourcesPath = "GlobalResources");
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("en-GB"),
new CultureInfo("cy-GB"),
new CultureInfo("cy"),
new CultureInfo("fr-FR"),
new CultureInfo("fr"),
};
// State what the default culture for your application is. This will be used if no specific culture
// can be determined for a given request.
options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
// You must explicitly state which cultures your application supports.
// These are the cultures the app supports for formatting numbers, dates, etc.
options.SupportedCultures = supportedCultures;
// These are the cultures the app supports for UI strings, i.e. we have localized resources for.
options.SupportedUICultures = supportedCultures;
// You can change which providers are configured to determine the culture for requests, or even add a custom
// provider with your own logic. The providers will be asked in order to provide a culture for each request,
// and the first to provide a non-null result that is in the configured supported cultures list will be used.
// By default, the following built-in providers are configured:
// - QueryStringRequestCultureProvider, sets culture via "culture" and "ui-culture" query string values, useful for testing
// - CookieRequestCultureProvider, sets culture via "ASPNET_CULTURE" cookie
// - AcceptLanguageHeaderRequestCultureProvider, sets culture via the "Accept-Language" request header
//options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
//{
// // My custom request culture logic
// return new ProviderCultureResult("en");
//}));
});
services.AddRouting(options =>
{
options.LowercaseUrls = true;
});
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
//.........这里部分代码省略.........
示例14: Register
public void Register(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<IConfiguration>(provider => Configuration);
serviceCollection.AddSingleton<IContentTypeProvider, FileExtensionContentTypeProvider>();
serviceCollection.AddSingleton<IThumbnailCacheService, ThumbnailCacheService>();
serviceCollection.AddSingleton<IEmailSender, AuthMessageSender>();
serviceCollection.AddSingleton<ISmsSender, AuthMessageSender>();
serviceCollection.AddSingleton<IAvatarService, AvatarService>();
serviceCollection.AddSingleton<IFileSystem>(provider =>
{
var webSettings = provider.GetService<ISettingsProvider<WebSettings>>();
var dataDirectory = provider.GetService<IPathResolver>().Resolve(webSettings.Settings.DataDirectory);
return new LocalFileSystem(dataDirectory);
});
serviceCollection.AddScoped<ApplicationUserStore>();
serviceCollection.AddScoped<IUserStore<User>>(provider => provider.GetService<ApplicationUserStore>());
serviceCollection.AddScoped<IRoleStore<Role>>(provider => provider.GetService<ApplicationUserStore>());
serviceCollection.AddScoped<IUserRoleStore<User>>(provider => provider.GetService<ApplicationUserStore>());
serviceCollection.AddScoped<IPasswordHasher<User>>(provider => provider.GetService<ApplicationUserStore>());
serviceCollection.AddScoped<IUserValidator<User>>(provider => provider.GetService<ApplicationUserStore>());
serviceCollection.AddScoped<ILookupNormalizer, ApplicationLookupNormalizer>();
serviceCollection.AddIdentity<User, Role>(options =>
{
options.Password.RequireNonLetterOrDigit = false;
options.Password.RequireUppercase = false;
}).AddDefaultTokenProviders();
serviceCollection.AddScoped<IViewComponentInvokerFactory, ViewComponentInvokerFactory>();
serviceCollection.AddMvc(options =>
{
options.ModelValidatorProviders.Add(new FluentValidationModelValidatorProvider());
});
serviceCollection.AddScoped<IUserContext, UserContext>();
serviceCollection.AddScoped<IContextService, ContextService>();
serviceCollection.AddSession();
serviceCollection.AddCaching(); // adds a default in-memory implementation of IDistributedCache
serviceCollection.AddRouting(options =>
{
options.LowercaseUrls = true;
});
serviceCollection.AddAuthorization(options =>
{
options.AddPolicy("Admin", policy =>
{
policy.RequireClaim(ClaimTypes.Role, "Admin");
});
});
serviceCollection.AddOptions();
serviceCollection.Configure<IdentityOptions>(options =>
{
options.Cookies.ApplicationCookie.Events = new CustomCookieAuthenticationEvents();
});
}
示例15: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddRouting();
}