From 6dfcfaa7eb8784f8f4357cb6e2f73f50429efe9e Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 8 Oct 2014 12:56:53 -0700 Subject: [PATCH] React to options changes --- samples/MvcSample.Web/Startup.cs | 6 +++--- src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs | 10 +++++----- .../MvcServiceCollectionExtensions.cs | 2 +- src/Microsoft.AspNet.Mvc/MvcServices.cs | 2 +- .../ActionResults/ObjectResultTests.cs | 2 +- .../InputObjectBindingTests.cs | 2 +- .../MockMvcOptionsAccessor.cs | 5 +++++ .../Validation/DefaultBodyModelValidatorTests.cs | 2 +- test/Microsoft.AspNet.Mvc.Test/MvcOptionSetupTest.cs | 12 ++++++------ test/WebSites/ApiExplorerWebSite/Startup.cs | 2 +- test/WebSites/CompositeViewEngine/Startup.cs | 2 +- test/WebSites/FiltersWebSite/Startup.cs | 2 +- test/WebSites/ModelBindingWebSite/Startup.cs | 2 +- test/WebSites/RazorWebSite/Startup.cs | 2 +- test/WebSites/UrlHelperWebSite/Startup.cs | 2 +- test/WebSites/ValueProvidersSite/Startup.cs | 2 +- test/WebSites/XmlSerializerWebSite/Startup.cs | 2 +- 17 files changed, 32 insertions(+), 27 deletions(-) diff --git a/samples/MvcSample.Web/Startup.cs b/samples/MvcSample.Web/Startup.cs index 76d0b496d1..6af40cad4d 100644 --- a/samples/MvcSample.Web/Startup.cs +++ b/samples/MvcSample.Web/Startup.cs @@ -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>(); - services.SetupOptions(options => + services.ConfigureOptions(options => { options.Filters.Add(typeof(PassThroughAttribute), order: 17); }); - services.SetupOptions(options => + services.ConfigureOptions(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>(); - services.SetupOptions(options => + services.ConfigureOptions(options => { options.Filters.Add(typeof(PassThroughAttribute), order: 17); }); diff --git a/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs b/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs index de1ab811db..3959a57f92 100644 --- a/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs +++ b/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs @@ -10,16 +10,16 @@ namespace Microsoft.AspNet.Mvc /// /// Sets up default options for . /// - public class MvcOptionsSetup : IOptionsSetup + public class MvcOptionsSetup : OptionsAction { - /// - public int Order + /// Sets the Order to -1 to allow MvcOptionsSetup to run before a user call to ConfigureOptions. + public MvcOptionsSetup() : base(ConfigureMvc) { - get { return DefaultOrder.DefaultFrameworkSortOrder; } + Order = -1; } /// - public void Setup(MvcOptions options) + public static void ConfigureMvc(MvcOptions options) { // Set up ViewEngines options.ViewEngines.Add(typeof(RazorViewEngine)); diff --git a/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs index c0bbd64713..0d890f26cf 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs @@ -26,7 +26,7 @@ namespace Microsoft.Framework.DependencyInjection private static void AddMvcRouteOptions(IServiceCollection services) { - services.SetupOptions(routeOptions => + services.ConfigureOptions(routeOptions => routeOptions.ConstraintMap .Add("exists", typeof(KnownRouteValueConstraint))); diff --git a/src/Microsoft.AspNet.Mvc/MvcServices.cs b/src/Microsoft.AspNet.Mvc/MvcServices.cs index bc55158dde..b735a4fcc2 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServices.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServices.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Mvc { var describe = new ServiceDescriber(configuration); - yield return describe.Transient, MvcOptionsSetup>(); + yield return describe.Transient, MvcOptionsSetup>(); yield return describe.Transient(); yield return describe.Singleton(); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectResultTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectResultTests.cs index d79051437a..6b5b5843da 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectResultTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectResultTests.cs @@ -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>(); optionsAccessor.SetupGet(o => o.Options).Returns(options); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/InputObjectBindingTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/InputObjectBindingTests.cs index 2cfd3b4524..c5f7d410e8 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/InputObjectBindingTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/InputObjectBindingTests.cs @@ -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>(); accessor.SetupGet(a => a.Options) .Returns(mvcOptions); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/MockMvcOptionsAccessor.cs b/test/Microsoft.AspNet.Mvc.Core.Test/MockMvcOptionsAccessor.cs index 47f936194f..f3e07d9ab4 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/MockMvcOptionsAccessor.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/MockMvcOptionsAccessor.cs @@ -13,5 +13,10 @@ namespace Microsoft.AspNet.Mvc } public MvcOptions Options { get; private set; } + + public MvcOptions GetNamedOptions(string name) + { + return Options; + } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/DefaultBodyModelValidatorTests.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/DefaultBodyModelValidatorTests.cs index 6ab7c721ae..be74654e5d 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/DefaultBodyModelValidatorTests.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Validation/DefaultBodyModelValidatorTests.cs @@ -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>(); accessor.SetupGet(a => a.Options) .Returns(mvcOptions); diff --git a/test/Microsoft.AspNet.Mvc.Test/MvcOptionSetupTest.cs b/test/Microsoft.AspNet.Mvc.Test/MvcOptionSetupTest.cs index 26b62dbf2c..c95f0a8244 100644 --- a/test/Microsoft.AspNet.Mvc.Test/MvcOptionSetupTest.cs +++ b/test/Microsoft.AspNet.Mvc.Test/MvcOptionSetupTest.cs @@ -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); diff --git a/test/WebSites/ApiExplorerWebSite/Startup.cs b/test/WebSites/ApiExplorerWebSite/Startup.cs index f2d68f8531..e16fccf7ba 100644 --- a/test/WebSites/ApiExplorerWebSite/Startup.cs +++ b/test/WebSites/ApiExplorerWebSite/Startup.cs @@ -19,7 +19,7 @@ namespace ApiExplorer services.AddMvc(configuration); services.AddSingleton(); - services.SetupOptions(options => + services.ConfigureOptions(options => { options.Filters.AddService(typeof(ApiExplorerDataFilter)); diff --git a/test/WebSites/CompositeViewEngine/Startup.cs b/test/WebSites/CompositeViewEngine/Startup.cs index 9f020df0ba..cc0c198e0c 100644 --- a/test/WebSites/CompositeViewEngine/Startup.cs +++ b/test/WebSites/CompositeViewEngine/Startup.cs @@ -18,7 +18,7 @@ namespace CompositeViewEngine { // Add a view engine as the first one in the list. services.AddMvc(configuration) - .SetupOptions(options => + .ConfigureOptions(options => { options.ViewEngines.Insert(0, typeof(TestViewEngine)); }); diff --git a/test/WebSites/FiltersWebSite/Startup.cs b/test/WebSites/FiltersWebSite/Startup.cs index 9cd88a4a27..8498e242fe 100644 --- a/test/WebSites/FiltersWebSite/Startup.cs +++ b/test/WebSites/FiltersWebSite/Startup.cs @@ -19,7 +19,7 @@ namespace FiltersWebSite { services.AddMvc(configuration); - services.SetupOptions(options => + services.ConfigureOptions(options => { options.Filters.Add(new GlobalExceptionFilter()); }); diff --git a/test/WebSites/ModelBindingWebSite/Startup.cs b/test/WebSites/ModelBindingWebSite/Startup.cs index 52546cf15b..8cc537e171 100644 --- a/test/WebSites/ModelBindingWebSite/Startup.cs +++ b/test/WebSites/ModelBindingWebSite/Startup.cs @@ -19,7 +19,7 @@ namespace ModelBindingWebSite { // Add MVC services to the services container services.AddMvc(configuration) - .SetupOptions(m => + .ConfigureOptions(m => { m.MaxModelValidationErrors = 8; }); diff --git a/test/WebSites/RazorWebSite/Startup.cs b/test/WebSites/RazorWebSite/Startup.cs index 8a1e125883..bcdc1e0ffa 100644 --- a/test/WebSites/RazorWebSite/Startup.cs +++ b/test/WebSites/RazorWebSite/Startup.cs @@ -17,7 +17,7 @@ namespace RazorWebSite // Add MVC services to the services container services.AddMvc(configuration); services.AddTransient(); - services.SetupOptions(options => + services.ConfigureOptions(options => { var expander = new LanguageViewLocationExpander( context => context.HttpContext.Request.Query["language-expander-value"]); diff --git a/test/WebSites/UrlHelperWebSite/Startup.cs b/test/WebSites/UrlHelperWebSite/Startup.cs index c5406535f4..8a088e4bc4 100644 --- a/test/WebSites/UrlHelperWebSite/Startup.cs +++ b/test/WebSites/UrlHelperWebSite/Startup.cs @@ -17,7 +17,7 @@ namespace UrlHelperWebSite // Set up application services app.UseServices(services => { - services.SetupOptions(optionsSetup => + services.ConfigureOptions(optionsSetup => { optionsSetup.ServeCDNContent = Convert.ToBoolean(configuration.Get("ServeCDNContent")); optionsSetup.CDNServerBaseUrl = configuration.Get("CDNServerBaseUrl"); diff --git a/test/WebSites/ValueProvidersSite/Startup.cs b/test/WebSites/ValueProvidersSite/Startup.cs index d119dabe66..e16ed6c481 100644 --- a/test/WebSites/ValueProvidersSite/Startup.cs +++ b/test/WebSites/ValueProvidersSite/Startup.cs @@ -18,7 +18,7 @@ namespace ValueProvidersSite { // Add MVC services to the services container services.AddMvc(configuration) - .SetupOptions(options => + .ConfigureOptions(options => { options.ValueProviderFactories.Insert(1, new CustomValueProviderFactory()); }); diff --git a/test/WebSites/XmlSerializerWebSite/Startup.cs b/test/WebSites/XmlSerializerWebSite/Startup.cs index 9876e21748..0cc1592249 100644 --- a/test/WebSites/XmlSerializerWebSite/Startup.cs +++ b/test/WebSites/XmlSerializerWebSite/Startup.cs @@ -20,7 +20,7 @@ namespace XmlSerializerWebSite // Add MVC services to the services container services.AddMvc(configuration); - services.SetupOptions(options => + services.ConfigureOptions(options => { options.InputFormatters.Clear(); options.InputFormatters.Insert(0, new XmlSerializerInputFormatter());