Replace ConfigureOptions with IConfigureOptions
This commit is contained in:
parent
17c6cfcb4e
commit
43a0a5a9f1
|
|
@ -1,6 +1,7 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
|
@ -10,19 +11,19 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
/// <summary>
|
||||
/// Sets up MVC default options for <see cref="RouteOptions"/>.
|
||||
/// </summary>
|
||||
public class MvcCoreRouteOptionsSetup : ConfigureOptions<RouteOptions>
|
||||
public class MvcCoreRouteOptionsSetup : IConfigureOptions<RouteOptions>
|
||||
{
|
||||
public MvcCoreRouteOptionsSetup()
|
||||
: base(ConfigureRouting)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the <see cref="RouteOptions"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The <see cref="RouteOptions"/>.</param>
|
||||
public static void ConfigureRouting(RouteOptions options)
|
||||
public void Configure(RouteOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
options.ConstraintMap.Add("exists", typeof(KnownRouteValueConstraint));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,10 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
|
|||
/// <summary>
|
||||
/// Sets up default options for <see cref="MvcDataAnnotationsLocalizationOptions"/>.
|
||||
/// </summary>
|
||||
public class MvcDataAnnotationsLocalizationOptionsSetup : ConfigureOptions<MvcDataAnnotationsLocalizationOptions>
|
||||
public class MvcDataAnnotationsLocalizationOptionsSetup : IConfigureOptions<MvcDataAnnotationsLocalizationOptions>
|
||||
{
|
||||
public MvcDataAnnotationsLocalizationOptionsSetup()
|
||||
: base(ConfigureMvc)
|
||||
{
|
||||
}
|
||||
|
||||
public static void ConfigureMvc(MvcDataAnnotationsLocalizationOptions options)
|
||||
/// <inheritdoc />
|
||||
public void Configure(MvcDataAnnotationsLocalizationOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
|
|
@ -11,28 +10,52 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
|
|||
/// <summary>
|
||||
/// Sets up default options for <see cref="MvcOptions"/>.
|
||||
/// </summary>
|
||||
public class MvcDataAnnotationsMvcOptionsSetup : ConfigureOptions<MvcOptions>
|
||||
public class MvcDataAnnotationsMvcOptionsSetup : IConfigureOptions<MvcOptions>
|
||||
{
|
||||
public MvcDataAnnotationsMvcOptionsSetup(IServiceProvider serviceProvider)
|
||||
: base(options => ConfigureMvc(options, serviceProvider))
|
||||
private readonly IStringLocalizerFactory _stringLocalizerFactory;
|
||||
private readonly IValidationAttributeAdapterProvider _validationAttributeAdapterProvider;
|
||||
private readonly IOptions<MvcDataAnnotationsLocalizationOptions> _dataAnnotationLocalizationOptions;
|
||||
|
||||
public MvcDataAnnotationsMvcOptionsSetup(
|
||||
IValidationAttributeAdapterProvider validationAttributeAdapterProvider,
|
||||
IOptions<MvcDataAnnotationsLocalizationOptions> dataAnnotationLocalizationOptions)
|
||||
{
|
||||
if (validationAttributeAdapterProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(validationAttributeAdapterProvider));
|
||||
}
|
||||
|
||||
if (dataAnnotationLocalizationOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(dataAnnotationLocalizationOptions));
|
||||
}
|
||||
|
||||
_validationAttributeAdapterProvider = validationAttributeAdapterProvider;
|
||||
_dataAnnotationLocalizationOptions = dataAnnotationLocalizationOptions;
|
||||
}
|
||||
|
||||
public static void ConfigureMvc(MvcOptions options, IServiceProvider serviceProvider)
|
||||
public MvcDataAnnotationsMvcOptionsSetup(
|
||||
IValidationAttributeAdapterProvider validationAttributeAdapterProvider,
|
||||
IOptions<MvcDataAnnotationsLocalizationOptions> dataAnnotationLocalizationOptions,
|
||||
IStringLocalizerFactory stringLocalizerFactory)
|
||||
: this(validationAttributeAdapterProvider, dataAnnotationLocalizationOptions)
|
||||
{
|
||||
var dataAnnotationLocalizationOptions =
|
||||
serviceProvider.GetRequiredService<IOptions<MvcDataAnnotationsLocalizationOptions>>();
|
||||
_stringLocalizerFactory = stringLocalizerFactory;
|
||||
}
|
||||
|
||||
// This service will be registered only if AddDataAnnotationsLocalization() is added to service collection.
|
||||
var stringLocalizerFactory = serviceProvider.GetService<IStringLocalizerFactory>();
|
||||
var validationAttributeAdapterProvider = serviceProvider.GetRequiredService<IValidationAttributeAdapterProvider>();
|
||||
public void Configure(MvcOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
options.ModelMetadataDetailsProviders.Add(new DataAnnotationsMetadataProvider(stringLocalizerFactory));
|
||||
options.ModelMetadataDetailsProviders.Add(new DataAnnotationsMetadataProvider(_stringLocalizerFactory));
|
||||
|
||||
options.ModelValidatorProviders.Add(new DataAnnotationsModelValidatorProvider(
|
||||
validationAttributeAdapterProvider,
|
||||
dataAnnotationLocalizationOptions,
|
||||
stringLocalizerFactory));
|
||||
_validationAttributeAdapterProvider,
|
||||
_dataAnnotationLocalizationOptions,
|
||||
_stringLocalizerFactory));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -15,52 +16,62 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
|
|||
/// <summary>
|
||||
/// Sets up JSON formatter options for <see cref="MvcOptions"/>.
|
||||
/// </summary>
|
||||
public class MvcJsonMvcOptionsSetup : ConfigureOptions<MvcOptions>
|
||||
public class MvcJsonMvcOptionsSetup : IConfigureOptions<MvcOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="MvcJsonMvcOptionsSetup"/>.
|
||||
/// </summary>
|
||||
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
|
||||
/// <param name="jsonOptions"></param>
|
||||
/// <param name="charPool"></param>
|
||||
/// <param name="objectPoolProvider"></param>
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
private readonly JsonSerializerSettings _jsonSerializerSettings;
|
||||
private readonly ArrayPool<char> _charPool;
|
||||
private readonly ObjectPoolProvider _objectPoolProvider;
|
||||
|
||||
public MvcJsonMvcOptionsSetup(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<MvcJsonOptions> jsonOptions,
|
||||
ArrayPool<char> charPool,
|
||||
ObjectPoolProvider objectPoolProvider)
|
||||
: base((options) => ConfigureMvc(
|
||||
options,
|
||||
jsonOptions.Value.SerializerSettings,
|
||||
loggerFactory,
|
||||
charPool,
|
||||
objectPoolProvider))
|
||||
{
|
||||
if (loggerFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(loggerFactory));
|
||||
}
|
||||
|
||||
if (jsonOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(jsonOptions));
|
||||
}
|
||||
|
||||
if (charPool == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(charPool));
|
||||
}
|
||||
|
||||
if (objectPoolProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(objectPoolProvider));
|
||||
}
|
||||
|
||||
_loggerFactory = loggerFactory;
|
||||
_jsonSerializerSettings = jsonOptions.Value.SerializerSettings;
|
||||
_charPool = charPool;
|
||||
_objectPoolProvider = objectPoolProvider;
|
||||
}
|
||||
|
||||
public static void ConfigureMvc(
|
||||
MvcOptions options,
|
||||
JsonSerializerSettings serializerSettings,
|
||||
ILoggerFactory loggerFactory,
|
||||
ArrayPool<char> charPool,
|
||||
ObjectPoolProvider objectPoolProvider)
|
||||
public void Configure(MvcOptions options)
|
||||
{
|
||||
options.OutputFormatters.Add(new JsonOutputFormatter(_jsonSerializerSettings, _charPool));
|
||||
|
||||
options.OutputFormatters.Add(new JsonOutputFormatter(serializerSettings, charPool));
|
||||
|
||||
var jsonInputLogger = loggerFactory.CreateLogger<JsonInputFormatter>();
|
||||
var jsonInputLogger = _loggerFactory.CreateLogger<JsonInputFormatter>();
|
||||
options.InputFormatters.Add(new JsonInputFormatter(
|
||||
jsonInputLogger,
|
||||
serializerSettings,
|
||||
charPool,
|
||||
objectPoolProvider));
|
||||
_jsonSerializerSettings,
|
||||
_charPool,
|
||||
_objectPoolProvider));
|
||||
|
||||
var jsonInputPatchLogger = loggerFactory.CreateLogger<JsonPatchInputFormatter>();
|
||||
var jsonInputPatchLogger = _loggerFactory.CreateLogger<JsonPatchInputFormatter>();
|
||||
options.InputFormatters.Add(new JsonPatchInputFormatter(
|
||||
jsonInputPatchLogger,
|
||||
serializerSettings,
|
||||
charPool,
|
||||
objectPoolProvider));
|
||||
_jsonSerializerSettings,
|
||||
_charPool,
|
||||
_objectPoolProvider));
|
||||
|
||||
options.FormatterMappings.SetMediaTypeMappingForFormat("json", MediaTypeHeaderValue.Parse("application/json"));
|
||||
|
||||
|
|
|
|||
|
|
@ -8,24 +8,16 @@ using Microsoft.Extensions.Options;
|
|||
namespace Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="ConfigureOptions{TOptions}"/> implementation which will add the
|
||||
/// A <see cref="IConfigureOptions{TOptions}"/> implementation which will add the
|
||||
/// data contract serializer formatters to <see cref="MvcOptions"/>.
|
||||
/// </summary>
|
||||
public class MvcXmlDataContractSerializerMvcOptionsSetup : ConfigureOptions<MvcOptions>
|
||||
public class MvcXmlDataContractSerializerMvcOptionsSetup : IConfigureOptions<MvcOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="MvcXmlDataContractSerializerMvcOptionsSetup"/>.
|
||||
/// </summary>
|
||||
public MvcXmlDataContractSerializerMvcOptionsSetup()
|
||||
: base(ConfigureMvc)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the data contract serializer formatters to <see cref="MvcOptions"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The <see cref="MvcOptions"/>.</param>
|
||||
public static void ConfigureMvc(MvcOptions options)
|
||||
public void Configure(MvcOptions options)
|
||||
{
|
||||
options.ModelMetadataDetailsProviders.Add(new DataMemberRequiredBindingMetadataProvider());
|
||||
|
||||
|
|
|
|||
|
|
@ -6,24 +6,16 @@ using Microsoft.Extensions.Options;
|
|||
namespace Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="ConfigureOptions{TOptions}"/> implementation which will add the
|
||||
/// A <see cref="IConfigureOptions{TOptions}"/> implementation which will add the
|
||||
/// XML serializer formatters to <see cref="MvcOptions"/>.
|
||||
/// </summary>
|
||||
public class MvcXmlSerializerMvcOptionsSetup : ConfigureOptions<MvcOptions>
|
||||
public class MvcXmlSerializerMvcOptionsSetup : IConfigureOptions<MvcOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MvcXmlSerializerMvcOptionsSetup"/>.
|
||||
/// </summary>
|
||||
public MvcXmlSerializerMvcOptionsSetup()
|
||||
: base(ConfigureMvc)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the XML serializer formatters to <see cref="MvcOptions"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The <see cref="MvcOptions"/>.</param>
|
||||
public static void ConfigureMvc(MvcOptions options)
|
||||
public void Configure(MvcOptions options)
|
||||
{
|
||||
options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
|
||||
options.InputFormatters.Add(new XmlSerializerInputFormatter());
|
||||
|
|
|
|||
|
|
@ -142,8 +142,10 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
|
||||
// DependencyContextRazorViewEngineOptionsSetup needs to run after RazorViewEngineOptionsSetup.
|
||||
// The ordering of the following two lines is important to ensure this behavior.
|
||||
#pragma warning disable 0618
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Transient<IConfigureOptions<RazorViewEngineOptions>, RazorViewEngineOptionsSetup>());
|
||||
#pragma warning restore 0618
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Transient<
|
||||
IConfigureOptions<RazorViewEngineOptions>,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||
|
|
@ -10,37 +9,36 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
/// <summary>
|
||||
/// Configures <see cref="MvcViewOptions"/> to use <see cref="RazorViewEngine"/>.
|
||||
/// </summary>
|
||||
public class MvcRazorMvcViewOptionsSetup : ConfigureOptions<MvcViewOptions>
|
||||
public class MvcRazorMvcViewOptionsSetup : IConfigureOptions<MvcViewOptions>
|
||||
{
|
||||
private readonly IRazorViewEngine _razorViewEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="MvcRazorMvcViewOptionsSetup"/>.
|
||||
/// </summary>
|
||||
/// <param name="razorViewEngine">The <see cref="IRazorViewEngine"/>.</param>
|
||||
public MvcRazorMvcViewOptionsSetup(IRazorViewEngine razorViewEngine)
|
||||
: base(options => ConfigureMvc(razorViewEngine, options))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures <paramref name="options"/> to use <see cref="RazorViewEngine"/>.
|
||||
/// </summary>
|
||||
/// <param name="razorViewEngine">The <see cref="IRazorViewEngine"/>.</param>
|
||||
/// <param name="options">The <see cref="MvcViewOptions"/> to configure.</param>
|
||||
public static void ConfigureMvc(
|
||||
IRazorViewEngine razorViewEngine,
|
||||
MvcViewOptions options)
|
||||
{
|
||||
if (razorViewEngine == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(razorViewEngine));
|
||||
}
|
||||
|
||||
_razorViewEngine = razorViewEngine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures <paramref name="options"/> to use <see cref="RazorViewEngine"/>.
|
||||
/// </summary>
|
||||
/// <param name="options">The <see cref="MvcViewOptions"/> to configure.</param>
|
||||
public void Configure(MvcViewOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
options.ViewEngines.Add(razorViewEngine);
|
||||
options.ViewEngines.Add(_razorViewEngine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Razor;
|
||||
|
|
@ -12,6 +13,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// <summary>
|
||||
/// Sets up default options for <see cref="RazorViewEngineOptions"/>.
|
||||
/// </summary>
|
||||
[Obsolete("This type is for internal use and will be removed in a future version.")]
|
||||
public class RazorViewEngineOptionsSetup : ConfigureOptions<RazorViewEngineOptions>
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore.Mvc.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
|
|
@ -13,31 +12,52 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
/// <summary>
|
||||
/// Sets up default options for <see cref="MvcViewOptions"/>.
|
||||
/// </summary>
|
||||
public class MvcViewOptionsSetup : ConfigureOptions<MvcViewOptions>
|
||||
public class MvcViewOptionsSetup : IConfigureOptions<MvcViewOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="MvcViewOptionsSetup"/>.
|
||||
/// </summary>
|
||||
public MvcViewOptionsSetup(IServiceProvider serviceProvider)
|
||||
: base(options => ConfigureMvc(options, serviceProvider))
|
||||
private readonly IOptions<MvcDataAnnotationsLocalizationOptions> _dataAnnotationsLocalizationOptions;
|
||||
private readonly IValidationAttributeAdapterProvider _validationAttributeAdapterProvider;
|
||||
private readonly IStringLocalizerFactory _stringLocalizerFactory;
|
||||
|
||||
public MvcViewOptionsSetup(
|
||||
IOptions<MvcDataAnnotationsLocalizationOptions> dataAnnotationLocalizationOptions,
|
||||
IValidationAttributeAdapterProvider validationAttributeAdapterProvider)
|
||||
{
|
||||
if (dataAnnotationLocalizationOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(dataAnnotationLocalizationOptions));
|
||||
}
|
||||
|
||||
if (validationAttributeAdapterProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(validationAttributeAdapterProvider));
|
||||
}
|
||||
|
||||
_dataAnnotationsLocalizationOptions = dataAnnotationLocalizationOptions;
|
||||
_validationAttributeAdapterProvider = validationAttributeAdapterProvider;
|
||||
}
|
||||
|
||||
public static void ConfigureMvc(
|
||||
MvcViewOptions options,
|
||||
IServiceProvider serviceProvider)
|
||||
public MvcViewOptionsSetup(
|
||||
IOptions<MvcDataAnnotationsLocalizationOptions> dataAnnotationOptions,
|
||||
IValidationAttributeAdapterProvider validationAttributeAdapterProvider,
|
||||
IStringLocalizerFactory stringLocalizerFactory)
|
||||
: this(dataAnnotationOptions, validationAttributeAdapterProvider)
|
||||
{
|
||||
var dataAnnotationsLocalizationOptions =
|
||||
serviceProvider.GetRequiredService<IOptions<MvcDataAnnotationsLocalizationOptions>>();
|
||||
var stringLocalizerFactory = serviceProvider.GetService<IStringLocalizerFactory>();
|
||||
var validationAttributeAdapterProvider = serviceProvider.GetRequiredService<IValidationAttributeAdapterProvider>();
|
||||
if (stringLocalizerFactory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stringLocalizerFactory));
|
||||
}
|
||||
|
||||
_stringLocalizerFactory = stringLocalizerFactory;
|
||||
}
|
||||
|
||||
public void Configure(MvcViewOptions options)
|
||||
{
|
||||
// Set up client validators
|
||||
options.ClientModelValidatorProviders.Add(new DefaultClientModelValidatorProvider());
|
||||
options.ClientModelValidatorProviders.Add(new DataAnnotationsClientModelValidatorProvider(
|
||||
validationAttributeAdapterProvider,
|
||||
dataAnnotationsLocalizationOptions,
|
||||
stringLocalizerFactory));
|
||||
_validationAttributeAdapterProvider,
|
||||
_dataAnnotationsLocalizationOptions,
|
||||
_stringLocalizerFactory));
|
||||
options.ClientModelValidatorProviders.Add(new NumericClientModelValidatorProvider());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,14 +8,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
/// <summary>
|
||||
/// Sets up default options for <see cref="MvcOptions"/>.
|
||||
/// </summary>
|
||||
public class TempDataMvcOptionsSetup : ConfigureOptions<MvcOptions>
|
||||
public class TempDataMvcOptionsSetup : IConfigureOptions<MvcOptions>
|
||||
{
|
||||
public TempDataMvcOptionsSetup()
|
||||
: base(ConfigureMvc)
|
||||
{
|
||||
}
|
||||
|
||||
public static void ConfigureMvc(MvcOptions options)
|
||||
public void Configure(MvcOptions options)
|
||||
{
|
||||
options.Filters.Add(new SaveTempDataAttribute());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
// 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.
|
||||
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Test.Internal
|
||||
{
|
||||
public class MvcDataAnnotationsMvcOptionsSetupTests
|
||||
{
|
||||
[Fact]
|
||||
public void MvcDataAnnotationsMvcOptionsSetup_ServiceConstructorWithoutIStringLocalizer()
|
||||
{
|
||||
// Arrange
|
||||
var services = new ServiceCollection();
|
||||
|
||||
services.AddSingleton<IHostingEnvironment>(Mock.Of<IHostingEnvironment>());
|
||||
services.AddSingleton<IValidationAttributeAdapterProvider, ValidationAttributeAdapterProvider>();
|
||||
services.AddSingleton<IOptions<MvcDataAnnotationsLocalizationOptions>>(
|
||||
new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>());
|
||||
services.AddSingleton<IConfigureOptions<MvcOptions>, MvcDataAnnotationsMvcOptionsSetup>();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
// Act
|
||||
var optionsSetup = serviceProvider.GetRequiredService<IConfigureOptions<MvcOptions>>();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(optionsSetup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Microsoft.AspNetCore.Mvc.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal;
|
||||
|
|
@ -10,9 +11,11 @@ using Microsoft.AspNetCore.Mvc.Internal;
|
|||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.IntegrationTests
|
||||
{
|
||||
|
|
@ -24,23 +27,31 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
|
|||
var optionsSetup = new MvcCoreMvcOptionsSetup(new TestHttpRequestStreamReaderFactory());
|
||||
optionsSetup.Configure(Value);
|
||||
|
||||
var collection = new ServiceCollection().AddOptions();
|
||||
collection.AddSingleton<ICompositeMetadataDetailsProvider, DefaultCompositeMetadataDetailsProvider>();
|
||||
collection.AddSingleton<IModelMetadataProvider, DefaultModelMetadataProvider>();
|
||||
collection.AddSingleton<IValidationAttributeAdapterProvider, ValidationAttributeAdapterProvider>();
|
||||
MvcDataAnnotationsMvcOptionsSetup.ConfigureMvc(
|
||||
Value,
|
||||
collection.BuildServiceProvider());
|
||||
var validationAttributeAdapterProvider = new ValidationAttributeAdapterProvider();
|
||||
var dataAnnotationLocalizationOptions = new TestOptionsManager<MvcDataAnnotationsLocalizationOptions>();
|
||||
var stringLocalizer = new Mock<IStringLocalizer>();
|
||||
var stringLocalizerFactory = new Mock<IStringLocalizerFactory>();
|
||||
stringLocalizerFactory
|
||||
.Setup(s => s.Create(It.IsAny<Type>()))
|
||||
.Returns(stringLocalizer.Object);
|
||||
|
||||
var dataAnnotationOptionsSetup = new MvcDataAnnotationsMvcOptionsSetup(
|
||||
validationAttributeAdapterProvider,
|
||||
dataAnnotationLocalizationOptions,
|
||||
stringLocalizerFactory.Object);
|
||||
dataAnnotationOptionsSetup.Configure(Value);
|
||||
|
||||
var loggerFactory = new LoggerFactory();
|
||||
var serializerSettings = JsonSerializerSettingsProvider.CreateSerializerSettings();
|
||||
var jsonOptions = new TestOptionsManager<MvcJsonOptions>();
|
||||
var charPool = ArrayPool<char>.Shared;
|
||||
var objectPoolProvider = new DefaultObjectPoolProvider();
|
||||
|
||||
MvcJsonMvcOptionsSetup.ConfigureMvc(
|
||||
Value,
|
||||
serializerSettings,
|
||||
var mvcJsonMvcOptionsSetup = new MvcJsonMvcOptionsSetup(
|
||||
loggerFactory,
|
||||
ArrayPool<char>.Shared,
|
||||
new DefaultObjectPoolProvider());
|
||||
jsonOptions,
|
||||
charPool,
|
||||
objectPoolProvider);
|
||||
mvcJsonMvcOptionsSetup.Configure(Value);
|
||||
}
|
||||
|
||||
public MvcOptions Value { get; }
|
||||
|
|
|
|||
|
|
@ -265,7 +265,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
var hostingEnvironment = new Mock<IHostingEnvironment>();
|
||||
hostingEnvironment.SetupGet(e => e.EnvironmentName)
|
||||
.Returns("Development");
|
||||
#pragma warning disable 0618
|
||||
var viewEngineSetup = new RazorViewEngineOptionsSetup(hostingEnvironment.Object);
|
||||
#pragma warning restore 0618
|
||||
|
||||
// Act
|
||||
viewEngineSetup.Configure(options);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// 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.
|
||||
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
|
@ -23,7 +23,9 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
.Returns(expected);
|
||||
hostingEnv.SetupGet(e => e.EnvironmentName)
|
||||
.Returns("Development");
|
||||
#pragma warning disable 0618
|
||||
var optionsSetup = new RazorViewEngineOptionsSetup(hostingEnv.Object);
|
||||
#pragma warning restore 0618
|
||||
|
||||
// Act
|
||||
optionsSetup.Configure(options);
|
||||
|
|
@ -44,7 +46,9 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
var hostingEnv = new Mock<IHostingEnvironment>();
|
||||
hostingEnv.SetupGet(e => e.EnvironmentName)
|
||||
.Returns(environment);
|
||||
#pragma warning disable 0618
|
||||
var optionsSetup = new RazorViewEngineOptionsSetup(hostingEnv.Object);
|
||||
#pragma warning restore 0618
|
||||
|
||||
// Act
|
||||
optionsSetup.Configure(options);
|
||||
|
|
@ -66,7 +70,9 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
var hostingEnv = new Mock<IHostingEnvironment>();
|
||||
hostingEnv.SetupGet(e => e.EnvironmentName)
|
||||
.Returns(environment);
|
||||
#pragma warning disable 0618
|
||||
var optionsSetup = new RazorViewEngineOptionsSetup(hostingEnv.Object);
|
||||
#pragma warning restore 0618
|
||||
|
||||
// Act
|
||||
optionsSetup.Configure(options);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
|
|
@ -1564,7 +1564,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Test
|
|||
IEnumerable<string> viewLocationFormats = null,
|
||||
IEnumerable<string> areaViewLocationFormats = null)
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
var optionsSetup = new RazorViewEngineOptionsSetup(Mock.Of<IHostingEnvironment>());
|
||||
#pragma warning restore 0618
|
||||
|
||||
var options = new RazorViewEngineOptions();
|
||||
optionsSetup.Configure(options);
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
|
|
@ -327,7 +327,9 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
typeof(IConfigureOptions<RazorViewEngineOptions>),
|
||||
new[]
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
typeof(RazorViewEngineOptionsSetup),
|
||||
#pragma warning restore 0618
|
||||
typeof(DependencyContextRazorViewEngineOptionsSetup)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue