React to options and hosting changes

This commit is contained in:
Hao Kung 2014-10-14 19:20:28 -07:00
parent 1680616fe5
commit 448ac5a0dc
73 changed files with 116 additions and 116 deletions

View File

@ -31,7 +31,7 @@ namespace MvcSample.Web
{
app.UseMiddleware<MonitoringMiddlware>();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc();
services.AddSingleton<PassThroughAttribute>();
@ -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<IAssemblyProvider, TestAssemblyProvider<Startup>>();
services.ConfigureOptions<MvcOptions>(options =>
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(typeof(PassThroughAttribute), order: 17);
});
services.ConfigureOptions<RazorViewEngineOptions>(options =>
services.Configure<RazorViewEngineOptions>(options =>
{
var expander = new LanguageViewLocationExpander(
context => context.HttpContext.Request.Query["language"]);
@ -72,7 +72,7 @@ namespace MvcSample.Web
else
#endif
{
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc();
services.AddSingleton<PassThroughAttribute>();
@ -83,7 +83,7 @@ namespace MvcSample.Web
// when the sample is used in the Functional Tests.
services.AddTransient<IAssemblyProvider, TestAssemblyProvider<Startup>>();
services.ConfigureOptions<MvcOptions>(options =>
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(typeof(PassThroughAttribute), order: 17);
});

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc
public AntiForgery([NotNull] IClaimUidExtractor claimUidExtractor,
[NotNull] IDataProtectionProvider dataProtectionProvider,
[NotNull] IAntiForgeryAdditionalDataProvider additionalDataProvider,
[NotNull] IOptionsAccessor<MvcOptions> mvcOptions)
[NotNull] IOptions<MvcOptions> mvcOptions)
{
var config = mvcOptions.Options.AntiForgeryOptions;
var serializer = new AntiForgeryTokenSerializer(dataProtectionProvider.CreateProtector(_purpose));

View File

@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Mvc
public ControllerActionDescriptorProvider(IAssemblyProvider assemblyProvider,
IActionDiscoveryConventions conventions,
IGlobalFilterProvider globalFilters,
IOptionsAccessor<MvcOptions> optionsAccessor)
IOptions<MvcOptions> optionsAccessor)
{
_assemblyProvider = assemblyProvider;
_conventions = conventions;

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.Filters
/// Creates a new instance of <see cref="DefaultGlobalFilterProvider"/>.
/// </summary>
/// <param name="optionsAccessor">The options accessor for <see cref="MvcOptions"/>.</param>
public DefaultGlobalFilterProvider(IOptionsAccessor<MvcOptions> optionsAccessor)
public DefaultGlobalFilterProvider(IOptions<MvcOptions> optionsAccessor)
{
var filters = optionsAccessor.Options.Filters;
_filters = filters.ToList();

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Mvc.OptionDescriptors
/// <param name="typeActivator">An <see cref="ITypeActivator"/> instance used to instantiate types.</param>
/// <param name="serviceProvider">A <see cref="IServiceProvider"/> instance that retrieves services from the
/// service collection.</param>
public DefaultInputFormattersProvider(IOptionsAccessor<MvcOptions> optionsAccessor,
public DefaultInputFormattersProvider(IOptions<MvcOptions> optionsAccessor,
ITypeActivator typeActivator,
IServiceProvider serviceProvider)
: base(optionsAccessor.Options.InputFormatters, typeActivator, serviceProvider)

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Mvc
/// <param name="typeActivator">An <see cref="ITypeActivator"/> instance used to instantiate types.</param>
/// <param name="serviceProvider">A <see cref="IServiceProvider"/> instance that retrieves services from the
/// service collection.</param>
public DefaultOutputFormattersProvider(IOptionsAccessor<MvcOptions> optionsAccessor,
public DefaultOutputFormattersProvider(IOptions<MvcOptions> optionsAccessor,
ITypeActivator typeActivator,
IServiceProvider serviceProvider)
: base(optionsAccessor.Options.OutputFormatters, typeActivator, serviceProvider)

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.Internal
{
throw new InvalidOperationException(Resources.FormatUnableToFindServices(
"IServiceCollection.AddMvc()",
"IApplicationBuilder.UsePerRequestServices(...)",
"IApplicationBuilder.UseServices(...)",
"IApplicationBuilder.UseMvc(...)"));
}
}

View File

@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Mvc
var actionContext = new ActionContext(context.HttpContext, context.RouteData, actionDescriptor);
var optionsAccessor = services.GetService<IOptionsAccessor<MvcOptions>>();
var optionsAccessor = services.GetService<IOptions<MvcOptions>>();
actionContext.ModelState.MaxAllowedErrors = optionsAccessor.Options.MaxModelValidationErrors;
var contextAccessor = services.GetService<IContextAccessor<ActionContext>>();

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Mvc.OptionDescriptors
/// <param name="serviceProvider">A <see cref="IServiceProvider"/> instance that retrieves services from the
/// service collection.</param>
public DefaultModelBindersProvider(
IOptionsAccessor<MvcOptions> optionsAccessor,
IOptions<MvcOptions> optionsAccessor,
ITypeActivator typeActivator,
IServiceProvider serviceProvider)
: base(optionsAccessor.Options.ModelBinders, typeActivator, serviceProvider)

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.OptionDescriptors
/// <param name="serviceProvider">A <see cref="IServiceProvider"/> instance that retrieves services from the
/// service collection.</param>
public DefaultModelValidatorProviderProvider(
IOptionsAccessor<MvcOptions> optionsAccessor,
IOptions<MvcOptions> optionsAccessor,
ITypeActivator typeActivator,
IServiceProvider serviceProvider)
: base(optionsAccessor.Options.ModelValidatorProviders, typeActivator, serviceProvider)

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.OptionDescriptors
/// <param name="serviceProvider">A <see cref="IServiceProvider"/> instance that retrieves services from the
/// service collection.</param>
public DefaultValueProviderFactoryProvider(
IOptionsAccessor<MvcOptions> optionsAccessor,
IOptions<MvcOptions> optionsAccessor,
ITypeActivator typeActivator,
IServiceProvider serviceProvider)
: base(optionsAccessor.Options.ValueProviderFactories, typeActivator, serviceProvider)

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Mvc.OptionDescriptors
/// <param name="serviceProvider">A <see cref="IServiceProvider"/> instance that retrieves services from the
/// service collection.</param>
public DefaultViewEngineProvider(
IOptionsAccessor<MvcOptions> optionsAccessor,
IOptions<MvcOptions> optionsAccessor,
ITypeActivator typeActivator,
IServiceProvider serviceProvider)
: base(optionsAccessor.Options.ViewEngines, typeActivator, serviceProvider)

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.Razor
private readonly IFileSystem _fileSystem;
private readonly TimeSpan _offset;
public ExpiringFileInfoCache(IOptionsAccessor<RazorViewEngineOptions> optionsAccessor)
public ExpiringFileInfoCache(IOptions<RazorViewEngineOptions> optionsAccessor)
{
_fileSystem = optionsAccessor.Options.FileSystem;
_offset = optionsAccessor.Options.ExpirationBeforeCheckingFilesOnDisk;

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.Razor.OptionDescriptors
/// <param name="serviceProvider">A <see cref="IServiceProvider"/> instance that retrieves services from the
/// service collection.</param>
public DefaultViewLocationExpanderProvider(
IOptionsAccessor<RazorViewEngineOptions> optionsAccessor,
IOptions<RazorViewEngineOptions> optionsAccessor,
ITypeActivator typeActivator,
IServiceProvider serviceProvider)
: base(optionsAccessor.Options.ViewLocationExpanders, typeActivator, serviceProvider)

View File

@ -22,13 +22,13 @@ namespace Microsoft.AspNet.Mvc.Razor
public RazorPreCompiler([NotNull] IServiceProvider designTimeServiceProvider) :
this(designTimeServiceProvider,
designTimeServiceProvider.GetService<IMvcRazorHost>(),
designTimeServiceProvider.GetService<IOptionsAccessor<RazorViewEngineOptions>>())
designTimeServiceProvider.GetService<IOptions<RazorViewEngineOptions>>())
{
}
public RazorPreCompiler([NotNull] IServiceProvider designTimeServiceProvider,
[NotNull] IMvcRazorHost host,
[NotNull] IOptionsAccessor<RazorViewEngineOptions> optionsAccessor)
[NotNull] IOptions<RazorViewEngineOptions> optionsAccessor)
{
_serviceProvider = designTimeServiceProvider;
_host = host;

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Mvc.Razor
private readonly IRazorPageFactory _pageFactory;
public ViewStartProvider(IRazorPageFactory pageFactory,
IOptionsAccessor<RazorViewEngineOptions> optionsAccessor)
IOptions<RazorViewEngineOptions> optionsAccessor)
{
_fileSystem = optionsAccessor.Options.FileSystem;
_pageFactory = pageFactory;

View File

@ -214,7 +214,7 @@ namespace System.Net.Http
if (formatters == null)
{
// Get the default formatters from options
var options = context.RequestServices.GetService<IOptionsAccessor<WebApiCompatShimOptions>>();
var options = context.RequestServices.GetService<IOptions<WebApiCompatShimOptions>>();
formatters = options.Options.Formatters;
}
@ -266,7 +266,7 @@ namespace System.Net.Http
var context = GetHttpContext(request);
// Get the default formatters from options
var options = context.RequestServices.GetService<IOptionsAccessor<WebApiCompatShimOptions>>();
var options = context.RequestServices.GetService<IOptions<WebApiCompatShimOptions>>();
var formatters = options.Options.Formatters;
var formatter = formatters.FindWriter(typeof(T), mediaType);

View File

@ -6,7 +6,7 @@ using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc.WebApiCompatShim
{
public class WebApiCompatShimOptionsSetup : IOptionsAction<MvcOptions>, IOptionsAction<WebApiCompatShimOptions>
public class WebApiCompatShimOptionsSetup : IConfigureOptions<MvcOptions>, IConfigureOptions<WebApiCompatShimOptions>
{
public readonly static string DefaultAreaName = "api";
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
public string Name { get; set; }
public void Invoke(MvcOptions options)
public void Configure(MvcOptions options, string name = "")
{
// Add webapi behaviors to controllers with the appropriate attributes
options.ApplicationModelConventions.Add(new WebApiActionConventionsGlobalModelConvention());
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
options.OutputFormatters.Insert(0, new HttpResponseMessageOutputFormatter());
}
public void Invoke(WebApiCompatShimOptions options)
public void Configure(WebApiCompatShimOptions options, string name = "")
{
// Add the default formatters
options.Formatters.AddRange(new MediaTypeFormatterCollection());

View File

@ -10,7 +10,7 @@ namespace Microsoft.Framework.DependencyInjection
{
public static IServiceCollection AddWebApiConventions(this IServiceCollection services)
{
services.AddOptionsAction<WebApiCompatShimOptionsSetup>();
services.ConfigureOptions<WebApiCompatShimOptionsSetup>();
// The constructors on DefaultContentNegotiator aren't DI friendly, so just
// new it up.

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc
/// <summary>
/// Sets up default options for <see cref="MvcOptions"/>.
/// </summary>
public class MvcOptionsSetup : OptionsAction<MvcOptions>
public class MvcOptionsSetup : ConfigureOptions<MvcOptions>
{
/// <remarks>Sets the Order to -1 to allow MvcOptionsSetup to run before a user call to ConfigureOptions.</remarks>
public MvcOptionsSetup() : base(ConfigureMvc)

View File

@ -26,7 +26,7 @@ namespace Microsoft.Framework.DependencyInjection
private static void AddMvcRouteOptions(IServiceCollection services)
{
services.ConfigureOptions<RouteOptions>(routeOptions =>
services.Configure<RouteOptions>(routeOptions =>
routeOptions.ConstraintMap
.Add("exists",
typeof(KnownRouteValueConstraint)));

View File

@ -34,9 +34,8 @@ namespace Microsoft.AspNet.Mvc
//
// Options and core services.
//
yield return describe.Transient<IOptionsAction<MvcOptions>, MvcOptionsSetup>();
yield return describe.Transient<IOptionsAction<RazorViewEngineOptions>, RazorViewEngineOptionsSetup>();
yield return describe.Transient<IConfigureOptions<MvcOptions>, MvcOptionsSetup>();
yield return describe.Transient<IConfigureOptions<RazorViewEngineOptions>, RazorViewEngineOptionsSetup>();
yield return describe.Transient<IAssemblyProvider, DefaultAssemblyProvider>();
yield return describe.Transient(typeof(INestedProviderManager<>), typeof(NestedProviderManager<>));
yield return describe.Transient(typeof(INestedProviderManagerAsync<>), typeof(NestedProviderManagerAsync<>));
@ -110,7 +109,7 @@ namespace Microsoft.AspNet.Mvc
// The host is designed to be discarded after consumption and is very inexpensive to initialize.
yield return describe.Transient<IMvcRazorHost>(serviceProvider =>
{
var optionsAccessor = serviceProvider.GetService<IOptionsAccessor<RazorViewEngineOptions>>();
var optionsAccessor = serviceProvider.GetService<IOptions<RazorViewEngineOptions>>();
return new MvcRazorHost(optionsAccessor.Options.FileSystem);
});

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc
= new ResourceManager("Microsoft.AspNet.Mvc.Resources", typeof(Resources).GetTypeInfo().Assembly);
/// <summary>
/// Unable to find the required services. Please add all the required services by calling AddMvc() before calling UseMvc()/UsePerRequestServices() in the Application Startup.
/// Unable to find the required services. Please add all the required services by calling AddMvc() before calling UseMvc()/UseServices() in the Application Startup.
/// </summary>
internal static string UnableToFindServices
{
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Mvc
}
/// <summary>
/// Unable to find the required services. Please add all the required services by calling AddMvc() before calling UseMvc()/UsePerRequestServices() in the Application Startup.
/// Unable to find the required services. Please add all the required services by calling AddMvc() before calling UseMvc()/UseServices() in the Application Startup.
/// </summary>
internal static string FormatUnableToFindServices()
{

View File

@ -30,8 +30,8 @@ namespace Microsoft.AspNet.Mvc
var appEnv = _appServices.GetService<IApplicationEnvironment>();
var setup = new RazorViewEngineOptionsSetup(appEnv);
var accessor = new OptionsAccessor<RazorViewEngineOptions>(new[] { setup });
sc.AddInstance<IOptionsAccessor<RazorViewEngineOptions>>(accessor);
var accessor = new OptionsManager<RazorViewEngineOptions>(new[] { setup });
sc.AddInstance<IOptions<RazorViewEngineOptions>>(accessor);
sc.Add(MvcServices.GetDefaultServices());
var sp = sc.BuildServiceProvider(_appServices);

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc
/// <summary>
/// Sets up default options for <see cref="RazorViewEngineOptions"/>.
/// </summary>
public class RazorViewEngineOptionsSetup : OptionsAction<RazorViewEngineOptions>
public class RazorViewEngineOptionsSetup : ConfigureOptions<RazorViewEngineOptions>
{
/// <summary>
/// Initializes a new instance of <see cref="RazorViewEngineOptions"/>.

View File

@ -521,12 +521,12 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
{
var optionsSetup = new MvcOptionsSetup();
var options = new MvcOptions();
optionsSetup.Invoke(options);
var optionsAccessor = new Mock<IOptionsAccessor<MvcOptions>>();
optionsSetup.Configure(options);
var optionsAccessor = new Mock<IOptions<MvcOptions>>();
optionsAccessor.SetupGet(o => o.Options).Returns(options);
var serviceCollection = new ServiceCollection();
serviceCollection.AddInstance<IOptionsAccessor<MvcOptions>>(optionsAccessor.Object);
serviceCollection.AddInstance<IOptions<MvcOptions>>(optionsAccessor.Object);
return serviceCollection.BuildServiceProvider();
}

View File

@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
var claimExtractor = new Mock<IClaimUidExtractor>();
var dataProtectionProvider = new Mock<IDataProtectionProvider>();
var additionalDataProvider = new Mock<IAntiForgeryAdditionalDataProvider>();
var optionsAccessor = new Mock<IOptionsAccessor<MvcOptions>>();
var optionsAccessor = new Mock<IOptions<MvcOptions>>();
optionsAccessor.SetupGet(o => o.Options).Returns(new MvcOptions());
return new AntiForgery(claimExtractor.Object,
dataProtectionProvider.Object,

View File

@ -1369,7 +1369,7 @@ namespace Microsoft.AspNet.Mvc.Test
private ControllerActionDescriptorProvider GetProvider(
TypeInfo type,
IOptionsAccessor<MvcOptions> options)
IOptions<MvcOptions> options)
{
var conventions = new StaticActionDiscoveryConventions(type);

View File

@ -131,8 +131,8 @@ namespace Microsoft.AspNet.Mvc
var mvcOptions = new MvcOptions();
var setup = new MvcOptionsSetup();
setup.Invoke(mvcOptions);
var accessor = new Mock<IOptionsAccessor<MvcOptions>>();
setup.Configure(mvcOptions);
var accessor = new Mock<IOptions<MvcOptions>>();
accessor.SetupGet(a => a.Options)
.Returns(mvcOptions);
var validatorProvider = new DefaultModelValidatorProviderProvider(

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc
services.Setup(o => o.GetService(typeof(IEnumerable<MvcMarkerService>)))
.Returns(new List<MvcMarkerService>());
var expectedMessage = "Unable to find the required services. Please add all the required " +
"services by calling 'IServiceCollection.AddMvc()' inside the call to 'IApplicationBuilder.UsePerRequestServices(...)' " +
"services by calling 'IServiceCollection.AddMvc()' inside the call to 'IApplicationBuilder.UseServices(...)' " +
"or 'IApplicationBuilder.UseMvc(...)' in the application startup code.";
// Act & Assert

View File

@ -5,7 +5,7 @@ using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc
{
public class MockMvcOptionsAccessor : IOptionsAccessor<MvcOptions>
public class MockMvcOptionsAccessor : IOptions<MvcOptions>
{
public MockMvcOptionsAccessor()
{

View File

@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Mvc
{
// Arrange
var expected = 199;
var optionsAccessor = new Mock<IOptionsAccessor<MvcOptions>>();
var optionsAccessor = new Mock<IOptions<MvcOptions>>();
var options = new MvcOptions
{
MaxModelValidationErrors = expected
@ -167,7 +167,7 @@ namespace Microsoft.AspNet.Mvc
IActionSelector actionSelector = null,
IActionInvokerFactory invokerFactory = null,
ILoggerFactory loggerFactory = null,
IOptionsAccessor<MvcOptions> optionsAccessor = null)
IOptions<MvcOptions> optionsAccessor = null)
{
var mockContextAccessor = new Mock<IContextAccessor<ActionContext>>();
mockContextAccessor.Setup(c => c.SetContextSource(
@ -207,7 +207,7 @@ namespace Microsoft.AspNet.Mvc
if (optionsAccessor == null)
{
var mockOptionsAccessor = new Mock<IOptionsAccessor<MvcOptions>>();
var mockOptionsAccessor = new Mock<IOptions<MvcOptions>>();
mockOptionsAccessor.SetupGet(o => o.Options)
.Returns(new MvcOptions());
@ -225,7 +225,7 @@ namespace Microsoft.AspNet.Mvc
.Returns(loggerFactory);
httpContext.Setup(h => h.RequestServices.GetService(typeof(IEnumerable<MvcMarkerService>)))
.Returns(new List<MvcMarkerService> { new MvcMarkerService() });
httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptionsAccessor<MvcOptions>)))
httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>)))
.Returns(optionsAccessor);
return new RouteContext(httpContext.Object);

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.OptionDescriptors
var options = new MvcOptions();
options.ModelBinders.Add(binder);
options.ModelBinders.Add(typeof(TestModelBinder));
var optionsAccessor = new Mock<IOptionsAccessor<MvcOptions>>();
var optionsAccessor = new Mock<IOptions<MvcOptions>>();
optionsAccessor.SetupGet(o => o.Options)
.Returns(options);
var activator = new TypeActivator();

View File

@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Mvc.OptionDescriptors
var options = new MvcOptions();
options.ModelValidatorProviders.Add(type);
options.ModelValidatorProviders.Add(validationProvider);
var accessor = new Mock<IOptionsAccessor<MvcOptions>>();
var accessor = new Mock<IOptions<MvcOptions>>();
accessor.SetupGet(a => a.Options)
.Returns(options);
var provider = new DefaultModelValidatorProviderProvider(accessor.Object,

View File

@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.OptionDescriptors
var options = new MvcOptions();
options.ValueProviderFactories.Add(valueProviderFactory);
options.ValueProviderFactories.Add(type);
var accessor = new Mock<IOptionsAccessor<MvcOptions>>();
var accessor = new Mock<IOptions<MvcOptions>>();
accessor.SetupGet(a => a.Options)
.Returns(options);
var provider = new DefaultValueProviderFactoryProvider(accessor.Object,

View File

@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.OptionDescriptors
var options = new MvcOptions();
options.ViewEngines.Add(viewEngine);
options.ViewEngines.Add(type);
var accessor = new Mock<IOptionsAccessor<MvcOptions>>();
var accessor = new Mock<IOptions<MvcOptions>>();
accessor.SetupGet(a => a.Options)
.Returns(options);
var provider = new DefaultViewEngineProvider(accessor.Object, typeActivator, serviceProvider.Object);

View File

@ -172,7 +172,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var claimExtractor = new Mock<IClaimUidExtractor>();
var dataProtectionProvider = new Mock<IDataProtectionProvider>();
var additionalDataProvider = new Mock<IAntiForgeryAdditionalDataProvider>();
var optionsAccessor = new Mock<IOptionsAccessor<MvcOptions>>();
var optionsAccessor = new Mock<IOptions<MvcOptions>>();
optionsAccessor.SetupGet(o => o.Options).Returns(new MvcOptions());
return new AntiForgery(claimExtractor.Object,
dataProtectionProvider.Object,

View File

@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Mvc.Routing
private static decimal Compute(string template)
{
var options = new Mock<IOptionsAccessor<RouteOptions>>();
var options = new Mock<IOptions<RouteOptions>>();
options.SetupGet(o => o.Options).Returns(new RouteOptions());
var constraintResolver = new DefaultInlineConstraintResolver(

View File

@ -1211,7 +1211,7 @@ namespace Microsoft.AspNet.Mvc.Routing
var services = Mock.Of<IServiceProvider>();
var options = new RouteOptions();
var optionsMock = new Mock<IOptionsAccessor<RouteOptions>>();
var optionsMock = new Mock<IOptions<RouteOptions>>();
optionsMock.SetupGet(o => o.Options).Returns(options);
return new DefaultInlineConstraintResolver(services, optionsMock.Object);

View File

@ -161,7 +161,7 @@ namespace Microsoft.AspNet.Mvc.Routing
.Setup(s => s.GetService(typeof(IActionDescriptorsCollectionProvider)))
.Returns(actionDescriptorProvider.Object);
var routeOptions = new Mock<IOptionsAccessor<RouteOptions>>();
var routeOptions = new Mock<IOptions<RouteOptions>>();
routeOptions
.SetupGet(o => o.Options)
.Returns(new RouteOptions());

View File

@ -641,7 +641,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
.Returns<VirtualPathContext>(rc => null);
rt.DefaultHandler = target.Object;
var serviceProviderMock = new Mock<IServiceProvider>();
var accessorMock = new Mock<IOptionsAccessor<RouteOptions>>();
var accessorMock = new Mock<IOptions<RouteOptions>>();
accessorMock.SetupGet(o => o.Options).Returns(new RouteOptions());
serviceProviderMock.Setup(o => o.GetService(typeof(IInlineConstraintResolver)))
.Returns(new DefaultInlineConstraintResolver(serviceProviderMock.Object,

View File

@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
// Arrange
var expectedMessage = "Unable to find the required services. Please add all the required " +
"services by calling 'IServiceCollection.AddMvc()' inside the call to 'IApplicationBuilder.UsePerRequestServices(...)' " +
"services by calling 'IServiceCollection.AddMvc()' inside the call to 'IApplicationBuilder.UseServices(...)' " +
"or 'IApplicationBuilder.UseMvc(...)' in the application startup code.";
// Act & Assert

View File

@ -9,6 +9,7 @@ using System.Linq;
using Microsoft.AspNet.Testing;
using Moq;
using Xunit;
using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc.ModelBinding
{

View File

@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.Razor
public DummyFileSystem TestFileSystem { get; } = new DummyFileSystem();
public IOptionsAccessor<RazorViewEngineOptions> OptionsAccessor
public IOptions<RazorViewEngineOptions> OptionsAccessor
{
get
{
@ -26,14 +26,14 @@ namespace Microsoft.AspNet.Mvc.Razor
FileSystem = TestFileSystem
};
var mock = new Mock<IOptionsAccessor<RazorViewEngineOptions>>(MockBehavior.Strict);
var mock = new Mock<IOptions<RazorViewEngineOptions>>(MockBehavior.Strict);
mock.Setup(oa => oa.Options).Returns(options);
return mock.Object;
}
}
public ControllableExpiringFileInfoCache GetCache(IOptionsAccessor<RazorViewEngineOptions> optionsAccessor)
public ControllableExpiringFileInfoCache GetCache(IOptions<RazorViewEngineOptions> optionsAccessor)
{
return new ControllableExpiringFileInfoCache(optionsAccessor);
}
@ -54,14 +54,14 @@ namespace Microsoft.AspNet.Mvc.Razor
cache.Sleep(offsetMilliseconds);
}
public void Sleep(IOptionsAccessor<RazorViewEngineOptions> accessor, ControllableExpiringFileInfoCache cache, int offsetMilliSeconds)
public void Sleep(IOptions<RazorViewEngineOptions> accessor, ControllableExpiringFileInfoCache cache, int offsetMilliSeconds)
{
var baseMilliSeconds = (int)accessor.Options.ExpirationBeforeCheckingFilesOnDisk.TotalMilliseconds;
cache.Sleep(baseMilliSeconds + offsetMilliSeconds);
}
public void SetExpiration(IOptionsAccessor<RazorViewEngineOptions> accessor, TimeSpan expiration)
public void SetExpiration(IOptions<RazorViewEngineOptions> accessor, TimeSpan expiration)
{
accessor.Options.ExpirationBeforeCheckingFilesOnDisk = expiration;
}
@ -307,7 +307,7 @@ namespace Microsoft.AspNet.Mvc.Razor
public class ControllableExpiringFileInfoCache : ExpiringFileInfoCache
{
public ControllableExpiringFileInfoCache(IOptionsAccessor<RazorViewEngineOptions> optionsAccessor)
public ControllableExpiringFileInfoCache(IOptions<RazorViewEngineOptions> optionsAccessor)
: base(optionsAccessor)
{
}

View File

@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.Razor.OptionDescriptors
var options = new RazorViewEngineOptions();
options.ViewLocationExpanders.Add(type);
options.ViewLocationExpanders.Add(expander);
var accessor = new Mock<IOptionsAccessor<RazorViewEngineOptions>>();
var accessor = new Mock<IOptions<RazorViewEngineOptions>>();
accessor.SetupGet(a => a.Options)
.Returns(options);
var provider = new DefaultViewLocationExpanderProvider(accessor.Object,

View File

@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc
var setup = new MvcOptionsSetup();
// Act
setup.Invoke(mvcOptions);
setup.Configure(mvcOptions);
// Assert
Assert.Equal(1, mvcOptions.ViewEngines.Count);
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc
var setup = new MvcOptionsSetup();
// Act
setup.Invoke(mvcOptions);
setup.Configure(mvcOptions);
// Assert
Assert.Equal(7, mvcOptions.ModelBinders.Count);
@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Mvc
var setup = new MvcOptionsSetup();
// Act
setup.Invoke(mvcOptions);
setup.Configure(mvcOptions);
// Assert
var valueProviders = mvcOptions.ValueProviderFactories;
@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Mvc
var setup = new MvcOptionsSetup();
// Act
setup.Invoke(mvcOptions);
setup.Configure(mvcOptions);
// Assert
Assert.Equal(4, mvcOptions.OutputFormatters.Count);
@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Mvc
var setup = new MvcOptionsSetup();
// Act
setup.Invoke(mvcOptions);
setup.Configure(mvcOptions);
// Assert
Assert.Equal(2, mvcOptions.InputFormatters.Count);
@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Mvc
var setup = new MvcOptionsSetup();
// Act
setup.Invoke(mvcOptions);
setup.Configure(mvcOptions);
// Assert
Assert.Equal(2, mvcOptions.ModelValidatorProviders.Count);

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Mvc
var optionsSetup = new RazorViewEngineOptionsSetup(appEnv.Object);
// Act
optionsSetup.Invoke(options);
optionsSetup.Configure(options);
// Assert
Assert.NotNull(options.FileSystem);

View File

@ -267,9 +267,9 @@ namespace System.Web.Http
var options = new MvcOptions();
var setup = new WebApiCompatShimOptionsSetup();
setup.Invoke(options);
setup.Configure(options);
var optionsAccessor = new Mock<IOptionsAccessor<MvcOptions>>();
var optionsAccessor = new Mock<IOptions<MvcOptions>>();
optionsAccessor
.SetupGet(o => o.Options)
.Returns(options);

View File

@ -30,11 +30,11 @@ namespace System.Net.Http
var options = new WebApiCompatShimOptions();
options.Formatters.AddRange(new MediaTypeFormatterCollection());
var optionsAccessor = new Mock<IOptionsAccessor<WebApiCompatShimOptions>>();
var optionsAccessor = new Mock<IOptions<WebApiCompatShimOptions>>();
optionsAccessor.SetupGet(o => o.Options).Returns(options);
services
.Setup(s => s.GetService(typeof(IOptionsAccessor<WebApiCompatShimOptions>)))
.Setup(s => s.GetService(typeof(IOptions<WebApiCompatShimOptions>)))
.Returns(optionsAccessor.Object);
context.RequestServices = services.Object;
@ -63,11 +63,11 @@ namespace System.Net.Http
var options = new WebApiCompatShimOptions();
options.Formatters.AddRange(new MediaTypeFormatterCollection());
var optionsAccessor = new Mock<IOptionsAccessor<WebApiCompatShimOptions>>();
var optionsAccessor = new Mock<IOptions<WebApiCompatShimOptions>>();
optionsAccessor.SetupGet(o => o.Options).Returns(options);
services
.Setup(s => s.GetService(typeof(IOptionsAccessor<WebApiCompatShimOptions>)))
.Setup(s => s.GetService(typeof(IOptions<WebApiCompatShimOptions>)))
.Returns(optionsAccessor.Object);
context.RequestServices = services.Object;
@ -326,12 +326,12 @@ namespace System.Net.Http
options.Formatters.Add(formatter);
}
var optionsAccessor = new Mock<IOptionsAccessor<WebApiCompatShimOptions>>();
var optionsAccessor = new Mock<IOptions<WebApiCompatShimOptions>>();
optionsAccessor.SetupGet(o => o.Options).Returns(options);
var services = new Mock<IServiceProvider>(MockBehavior.Strict);
services
.Setup(s => s.GetService(typeof(IOptionsAccessor<WebApiCompatShimOptions>)))
.Setup(s => s.GetService(typeof(IOptions<WebApiCompatShimOptions>)))
.Returns(optionsAccessor.Object);
if (contentNegotiator != null)

View File

@ -14,7 +14,7 @@ namespace ActivatorWebSite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);

View File

@ -9,7 +9,7 @@ namespace AntiForgeryWebSite
public void Configure(IApplicationBuilder app)
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc(configuration);
});

View File

@ -14,12 +14,12 @@ namespace ApiExplorer
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc(configuration);
services.AddSingleton<ApiExplorerDataFilter>();
services.ConfigureOptions<MvcOptions>(options =>
services.Configure<MvcOptions>(options =>
{
options.Filters.AddService(typeof(ApiExplorerDataFilter));

View File

@ -12,7 +12,7 @@ namespace ApplicationModelWebSite
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc(configuration);
});

View File

@ -13,7 +13,7 @@ namespace AutofacWebSite
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services => {
app.UseServices(services => {
services.AddMvc(configuration);
services.AddTransient<HelloWorldBuilder>();

View File

@ -13,7 +13,7 @@ namespace BasicWebSite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);

View File

@ -14,11 +14,11 @@ namespace CompositeViewEngine
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add a view engine as the first one in the list.
services.AddMvc(configuration)
.ConfigureOptions<MvcOptions>(options =>
.Configure<MvcOptions>(options =>
{
options.ViewEngines.Insert(0, typeof(TestViewEngine));
});

View File

@ -14,7 +14,7 @@ namespace ConnegWebsite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);

View File

@ -13,7 +13,7 @@ namespace FilesWebSite
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc(configuration);
});

View File

@ -15,11 +15,11 @@ namespace FiltersWebSite
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc(configuration);
services.ConfigureOptions<MvcOptions>(options =>
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new GlobalExceptionFilter());
});

View File

@ -14,7 +14,7 @@ namespace FormatterWebSite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);

View File

@ -38,7 +38,7 @@ namespace InlineConstraints
}
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);

View File

@ -15,11 +15,11 @@ namespace ModelBindingWebSite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration)
.ConfigureOptions<MvcOptions>(m =>
.Configure<MvcOptions>(m =>
{
m.MaxModelValidationErrors = 8;
});

View File

@ -17,7 +17,7 @@ namespace RazorInstrumentationWebSite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);

View File

@ -12,12 +12,12 @@ namespace RazorWebSite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);
services.AddTransient<InjectedHelper>();
services.ConfigureOptions<RazorViewEngineOptions>(options =>
services.Configure<RazorViewEngineOptions>(options =>
{
var expander = new LanguageViewLocationExpander(
context => context.HttpContext.Request.Query["language-expander-value"]);

View File

@ -13,7 +13,7 @@ namespace RoutingWebSite
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc(configuration);

View File

@ -12,7 +12,7 @@ namespace TagHelpersWebSite
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc(configuration);
});

View File

@ -14,11 +14,11 @@ namespace UrlHelperWebSite
/// </summary>
public class CustomUrlHelper : UrlHelper
{
private readonly IOptionsAccessor<AppOptions> _appOptions;
private readonly IOptions<AppOptions> _appOptions;
private readonly HttpContext _httpContext;
public CustomUrlHelper(IContextAccessor<ActionContext> contextAccessor, IActionSelector actionSelector,
IOptionsAccessor<AppOptions> appOptions)
IOptions<AppOptions> appOptions)
: base(contextAccessor, actionSelector)
{
_appOptions = appOptions;

View File

@ -14,9 +14,9 @@ namespace UrlHelperWebSite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.ConfigureOptions<AppOptions>(optionsSetup =>
services.Configure<AppOptions>(optionsSetup =>
{
optionsSetup.ServeCDNContent = true;
optionsSetup.CDNServerBaseUrl = "http://cdn.contoso.com";

View File

@ -14,11 +14,11 @@ namespace ValueProvidersSite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration)
.ConfigureOptions<MvcOptions>(options =>
.Configure<MvcOptions>(options =>
{
options.ValueProviderFactories.Insert(1, new CustomValueProviderFactory());
});

View File

@ -12,7 +12,7 @@ namespace VersioningWebSite
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc(configuration);

View File

@ -16,7 +16,7 @@ namespace WebApiCompatShimWebSite
public class BasicApiController : ApiController
{
[Activate]
public IOptionsAccessor<WebApiCompatShimOptions> OptionsAccessor { get; set; }
public IOptions<WebApiCompatShimOptions> OptionsAccessor { get; set; }
// Verifies property activation
[HttpGet]

View File

@ -13,7 +13,7 @@ namespace WebApiCompatShimWebSite
{
var configuration = app.GetTestConfiguration();
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
services.AddMvc(configuration);

View File

@ -15,12 +15,12 @@ namespace XmlSerializerWebSite
var configuration = app.GetTestConfiguration();
// Set up application services
app.UsePerRequestServices(services =>
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);
services.ConfigureOptions<MvcOptions>(options =>
services.Configure<MvcOptions>(options =>
{
options.InputFormatters.Clear();
options.InputFormatters.Insert(0, new XmlSerializerInputFormatter());