Reacting to new middleware options pattern

This commit is contained in:
John Luo 2016-01-08 18:07:36 -08:00
parent 2eb6cd655b
commit c8a59d7f3e
4 changed files with 17 additions and 15 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using InlineConstraintSample.Web.Constraints; using InlineConstraintSample.Web.Constraints;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting;
@ -25,11 +26,11 @@ namespace InlineConstraintSample.Web
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app)
{ {
app.UseRequestLocalization(localizationOptions => app.UseRequestLocalization(new RequestLocalizationOptions
{ {
// Ignore ambient and client locale. Use same values as ReplaceCultureAttribute / CultureReplacerMiddleware. // Ignore ambient and client locale. Use same values as ReplaceCultureAttribute / CultureReplacerMiddleware.
localizationOptions.DefaultRequestCulture = new RequestCulture("en-GB", "en-US"); DefaultRequestCulture = new RequestCulture("en-GB", "en-US"),
localizationOptions.RequestCultureProviders.Clear(); RequestCultureProviders = new List<IRequestCultureProvider>()
}); });
app.UseMvc(); app.UseMvc();

View File

@ -22,19 +22,19 @@ namespace LocalizationSample.Web
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app)
{ {
app.UseRequestLocalization(options => app.UseRequestLocalization(new RequestLocalizationOptions
{ {
options.DefaultRequestCulture = new RequestCulture("en-US"); DefaultRequestCulture = new RequestCulture("en-US"),
options.SupportedCultures = new List<CultureInfo> SupportedCultures = new List<CultureInfo>
{ {
new CultureInfo("fr"), new CultureInfo("fr"),
new CultureInfo("en-GB"), new CultureInfo("en-GB"),
}; },
options.SupportedUICultures = new List<CultureInfo> SupportedUICultures = new List<CultureInfo>
{ {
new CultureInfo("fr"), new CultureInfo("fr"),
new CultureInfo("en-GB"), new CultureInfo("en-GB"),
}; }
}); });
app.UseMvcWithDefaultRoute(); app.UseMvcWithDefaultRoute();

View File

@ -301,6 +301,7 @@ namespace Microsoft.AspNet.Mvc.Filters
var serviceCollection = new ServiceCollection(); var serviceCollection = new ServiceCollection();
if (registerServices != null) if (registerServices != null)
{ {
serviceCollection.AddOptions();
serviceCollection.AddLogging(); serviceCollection.AddLogging();
registerServices(serviceCollection); registerServices(serviceCollection);
} }

View File

@ -43,21 +43,21 @@ namespace RazorWebSite
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app)
{ {
app.UseRequestLocalization(options => app.UseRequestLocalization(new RequestLocalizationOptions
{ {
options.DefaultRequestCulture = new RequestCulture("en-GB", "en-US"); DefaultRequestCulture = new RequestCulture("en-GB", "en-US"),
options.SupportedCultures = new List<CultureInfo> SupportedCultures = new List<CultureInfo>
{ {
new CultureInfo("fr"), new CultureInfo("fr"),
new CultureInfo("en-GB"), new CultureInfo("en-GB"),
new CultureInfo("en-US"), new CultureInfo("en-US"),
}; },
options.SupportedUICultures = new List<CultureInfo> SupportedUICultures = new List<CultureInfo>
{ {
new CultureInfo("fr"), new CultureInfo("fr"),
new CultureInfo("en-GB"), new CultureInfo("en-GB"),
new CultureInfo("en-US"), new CultureInfo("en-US"),
}; }
}); });
app.UseMvcWithDefaultRoute(); app.UseMvcWithDefaultRoute();