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