зеркало из https://github.com/aspnet/Mvc.git
React to options changes
This commit is contained in:
Родитель
d3ef91ea91
Коммит
6dfcfaa7eb
|
@ -42,11 +42,11 @@ namespace MvcSample.Web
|
|||
// sample's assemblies are loaded. This prevents loading controllers from other assemblies
|
||||
// when the sample is used in the Functional Tests.
|
||||
services.AddTransient<IControllerAssemblyProvider, TestAssemblyProvider<Startup>>();
|
||||
services.SetupOptions<MvcOptions>(options =>
|
||||
services.ConfigureOptions<MvcOptions>(options =>
|
||||
{
|
||||
options.Filters.Add(typeof(PassThroughAttribute), order: 17);
|
||||
});
|
||||
services.SetupOptions<RazorViewEngineOptions>(options =>
|
||||
services.ConfigureOptions<RazorViewEngineOptions>(options =>
|
||||
{
|
||||
var expander = new LanguageViewLocationExpander(
|
||||
context => context.HttpContext.Request.Query["language"]);
|
||||
|
@ -83,7 +83,7 @@ namespace MvcSample.Web
|
|||
// when the sample is used in the Functional Tests.
|
||||
services.AddTransient<IControllerAssemblyProvider, TestAssemblyProvider<Startup>>();
|
||||
|
||||
services.SetupOptions<MvcOptions>(options =>
|
||||
services.ConfigureOptions<MvcOptions>(options =>
|
||||
{
|
||||
options.Filters.Add(typeof(PassThroughAttribute), order: 17);
|
||||
});
|
||||
|
|
|
@ -10,16 +10,16 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// <summary>
|
||||
/// Sets up default options for <see cref="MvcOptions"/>.
|
||||
/// </summary>
|
||||
public class MvcOptionsSetup : IOptionsSetup<MvcOptions>
|
||||
public class MvcOptionsSetup : OptionsAction<MvcOptions>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int Order
|
||||
/// <remarks>Sets the Order to -1 to allow MvcOptionsSetup to run before a user call to ConfigureOptions.</remarks>
|
||||
public MvcOptionsSetup() : base(ConfigureMvc)
|
||||
{
|
||||
get { return DefaultOrder.DefaultFrameworkSortOrder; }
|
||||
Order = -1;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Setup(MvcOptions options)
|
||||
public static void ConfigureMvc(MvcOptions options)
|
||||
{
|
||||
// Set up ViewEngines
|
||||
options.ViewEngines.Add(typeof(RazorViewEngine));
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
|
||||
private static void AddMvcRouteOptions(IServiceCollection services)
|
||||
{
|
||||
services.SetupOptions<RouteOptions>(routeOptions =>
|
||||
services.ConfigureOptions<RouteOptions>(routeOptions =>
|
||||
routeOptions.ConstraintMap
|
||||
.Add("exists",
|
||||
typeof(KnownRouteValueConstraint)));
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
var describe = new ServiceDescriber(configuration);
|
||||
|
||||
yield return describe.Transient<IOptionsSetup<MvcOptions>, MvcOptionsSetup>();
|
||||
yield return describe.Transient<IOptionsAction<MvcOptions>, MvcOptionsSetup>();
|
||||
|
||||
yield return describe.Transient<IControllerFactory, DefaultControllerFactory>();
|
||||
yield return describe.Singleton<IControllerActivator, DefaultControllerActivator>();
|
||||
|
|
|
@ -521,7 +521,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
|
|||
{
|
||||
var optionsSetup = new MvcOptionsSetup();
|
||||
var options = new MvcOptions();
|
||||
optionsSetup.Setup(options);
|
||||
optionsSetup.Invoke(options);
|
||||
var optionsAccessor = new Mock<IOptionsAccessor<MvcOptions>>();
|
||||
optionsAccessor.SetupGet(o => o.Options).Returns(options);
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var mvcOptions = new MvcOptions();
|
||||
var setup = new MvcOptionsSetup();
|
||||
|
||||
setup.Setup(mvcOptions);
|
||||
setup.Invoke(mvcOptions);
|
||||
var accessor = new Mock<IOptionsAccessor<MvcOptions>>();
|
||||
accessor.SetupGet(a => a.Options)
|
||||
.Returns(mvcOptions);
|
||||
|
|
|
@ -13,5 +13,10 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
|
||||
public MvcOptions Options { get; private set; }
|
||||
|
||||
public MvcOptions GetNamedOptions(string name)
|
||||
{
|
||||
return Options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -297,7 +297,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
var modelStateDictionary = new ModelStateDictionary();
|
||||
var mvcOptions = new MvcOptions();
|
||||
var setup = new MvcOptionsSetup();
|
||||
setup.Setup(mvcOptions);
|
||||
setup.Invoke(mvcOptions);
|
||||
var accessor = new Mock<IOptionsAccessor<MvcOptions>>();
|
||||
accessor.SetupGet(a => a.Options)
|
||||
.Returns(mvcOptions);
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var setup = new MvcOptionsSetup();
|
||||
|
||||
// Act
|
||||
setup.Setup(mvcOptions);
|
||||
setup.Invoke(mvcOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1, mvcOptions.ViewEngines.Count);
|
||||
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var setup = new MvcOptionsSetup();
|
||||
|
||||
// Act
|
||||
setup.Setup(mvcOptions);
|
||||
setup.Invoke(mvcOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(6, mvcOptions.ModelBinders.Count);
|
||||
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var setup = new MvcOptionsSetup();
|
||||
|
||||
// Act
|
||||
setup.Setup(mvcOptions);
|
||||
setup.Invoke(mvcOptions);
|
||||
|
||||
// Assert
|
||||
var valueProviders = mvcOptions.ValueProviderFactories;
|
||||
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var setup = new MvcOptionsSetup();
|
||||
|
||||
// Act
|
||||
setup.Setup(mvcOptions);
|
||||
setup.Invoke(mvcOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(4, mvcOptions.OutputFormatters.Count);
|
||||
|
@ -88,7 +88,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var setup = new MvcOptionsSetup();
|
||||
|
||||
// Act
|
||||
setup.Setup(mvcOptions);
|
||||
setup.Invoke(mvcOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, mvcOptions.InputFormatters.Count);
|
||||
|
@ -104,7 +104,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var setup = new MvcOptionsSetup();
|
||||
|
||||
// Act
|
||||
setup.Setup(mvcOptions);
|
||||
setup.Invoke(mvcOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, mvcOptions.ModelValidatorProviders.Count);
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace ApiExplorer
|
|||
services.AddMvc(configuration);
|
||||
services.AddSingleton<ApiExplorerDataFilter>();
|
||||
|
||||
services.SetupOptions<MvcOptions>(options =>
|
||||
services.ConfigureOptions<MvcOptions>(options =>
|
||||
{
|
||||
options.Filters.AddService(typeof(ApiExplorerDataFilter));
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace CompositeViewEngine
|
|||
{
|
||||
// Add a view engine as the first one in the list.
|
||||
services.AddMvc(configuration)
|
||||
.SetupOptions<MvcOptions>(options =>
|
||||
.ConfigureOptions<MvcOptions>(options =>
|
||||
{
|
||||
options.ViewEngines.Insert(0, typeof(TestViewEngine));
|
||||
});
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace FiltersWebSite
|
|||
{
|
||||
services.AddMvc(configuration);
|
||||
|
||||
services.SetupOptions<MvcOptions>(options =>
|
||||
services.ConfigureOptions<MvcOptions>(options =>
|
||||
{
|
||||
options.Filters.Add(new GlobalExceptionFilter());
|
||||
});
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace ModelBindingWebSite
|
|||
{
|
||||
// Add MVC services to the services container
|
||||
services.AddMvc(configuration)
|
||||
.SetupOptions<MvcOptions>(m =>
|
||||
.ConfigureOptions<MvcOptions>(m =>
|
||||
{
|
||||
m.MaxModelValidationErrors = 8;
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace RazorWebSite
|
|||
// Add MVC services to the services container
|
||||
services.AddMvc(configuration);
|
||||
services.AddTransient<InjectedHelper>();
|
||||
services.SetupOptions<RazorViewEngineOptions>(options =>
|
||||
services.ConfigureOptions<RazorViewEngineOptions>(options =>
|
||||
{
|
||||
var expander = new LanguageViewLocationExpander(
|
||||
context => context.HttpContext.Request.Query["language-expander-value"]);
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace UrlHelperWebSite
|
|||
// Set up application services
|
||||
app.UseServices(services =>
|
||||
{
|
||||
services.SetupOptions<AppOptions>(optionsSetup =>
|
||||
services.ConfigureOptions<AppOptions>(optionsSetup =>
|
||||
{
|
||||
optionsSetup.ServeCDNContent = Convert.ToBoolean(configuration.Get("ServeCDNContent"));
|
||||
optionsSetup.CDNServerBaseUrl = configuration.Get("CDNServerBaseUrl");
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace ValueProvidersSite
|
|||
{
|
||||
// Add MVC services to the services container
|
||||
services.AddMvc(configuration)
|
||||
.SetupOptions<MvcOptions>(options =>
|
||||
.ConfigureOptions<MvcOptions>(options =>
|
||||
{
|
||||
options.ValueProviderFactories.Insert(1, new CustomValueProviderFactory());
|
||||
});
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace XmlSerializerWebSite
|
|||
// Add MVC services to the services container
|
||||
services.AddMvc(configuration);
|
||||
|
||||
services.SetupOptions<MvcOptions>(options =>
|
||||
services.ConfigureOptions<MvcOptions>(options =>
|
||||
{
|
||||
options.InputFormatters.Clear();
|
||||
options.InputFormatters.Insert(0, new XmlSerializerInputFormatter());
|
||||
|
|
Загрузка…
Ссылка в новой задаче