Skip to content

Commit

Permalink
Remove deprecated registration options
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremySkinner committed Dec 17, 2022
1 parent f816b5b commit 9fd83ea
Showing 1 changed file with 2 additions and 121 deletions.
123 changes: 2 additions & 121 deletions src/FluentValidation.AspNetCore/FluentValidationMvcConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
namespace FluentValidation.AspNetCore;

using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;

/// <summary>
/// Auto-validation configuration.
Expand All @@ -46,13 +43,13 @@ public class FluentValidationAutoValidationConfiguration {
/// <summary>
/// The type of validator factory to use. Uses the ServiceProviderValidatorFactory by default.
/// </summary>
[Obsolete("IValidatorFactory and its implementors are deprecated. Please use the Service Provider directly. For details see https://github.com/FluentValidation/FluentValidation/issues/1961")]
[Obsolete("IValidatorFactory and its implementors are deprecated and will be removed in FluentValidation 13. Please use the Service Provider directly. For details see https://github.com/FluentValidation/FluentValidation/issues/1961")]
public Type ValidatorFactoryType { get; set; }

/// <summary>
/// The validator factory to use. Uses the ServiceProviderValidatorFactory by default.
/// </summary>
[Obsolete("IValidatorFactory and its implementors are deprecated. Please use the Service Provider directly. For details see https://github.com/FluentValidation/FluentValidation/issues/1961")]
[Obsolete("IValidatorFactory and its implementors are deprecated and will be removed in FluentValidation 13. Please use the Service Provider directly. For details see https://github.com/FluentValidation/FluentValidation/issues/1961")]
public IValidatorFactory ValidatorFactory { get; set; }

/// <summary>
Expand All @@ -61,119 +58,3 @@ public class FluentValidationAutoValidationConfiguration {
/// </summary>
public bool DisableDataAnnotationsValidation { get; set; }
}

/// <summary>
/// FluentValidation asp.net core configuration
/// </summary>
public class FluentValidationMvcConfiguration : FluentValidationAutoValidationConfiguration {
private readonly IServiceCollection _services;

[Obsolete]
public FluentValidationMvcConfiguration(ValidatorConfiguration validatorOptions) {
#pragma warning disable CS0618
ValidatorOptions = validatorOptions;
#pragma warning restore CS0618
}

internal FluentValidationMvcConfiguration(ValidatorConfiguration validatorOptions, IServiceCollection services) {
_services = services;
#pragma warning disable CS0618
ValidatorOptions = validatorOptions;
#pragma warning restore CS0618
}

/// <summary>
/// Options that are used to configure all validators.
/// </summary>
[Obsolete("Global options should be set using the static ValidatorOptions.Global instead.")]
public ValidatorConfiguration ValidatorOptions { get; private set; }

/// <summary>
/// Enables or disables localization support within FluentValidation
/// </summary>
[Obsolete("Set the static ValidatorOptions.Global.LanguageManager.Enabled property instead.")]
public bool LocalizationEnabled {
get => ValidatorOptions.LanguageManager.Enabled;
set => ValidatorOptions.LanguageManager.Enabled = value;
}

internal bool ClientsideEnabled = true;
internal Action<FluentValidationClientModelValidatorProvider> ClientsideConfig = x => {};

/// <summary>
/// Whether automatic server-side validation should be enabled (default true).
/// </summary>
public bool AutomaticValidationEnabled { get; set; } = true;

/// <summary>
/// Registers all validators derived from AbstractValidator within the assembly containing the specified type
/// </summary>
/// <param name="filter">Optional filter that allows certain types to be skipped from registration.</param>
/// <param name="lifetime">The service lifetime that should be used for the validator registration. Defaults to Scoped</param>
/// <param name="includeInternalTypes">Include internal validators. The default is false.</param>
[Obsolete("RegisterValidatorsFromAssemblyContaining is deprecated. Call services.AddValidatorsFromAssemblyContaining<T> instead, which has the same effect. See https://github.com/FluentValidation/FluentValidation/issues/1963")]
public FluentValidationMvcConfiguration RegisterValidatorsFromAssemblyContaining<T>(Func<AssemblyScanner.AssemblyScanResult, bool> filter = null, ServiceLifetime lifetime = ServiceLifetime.Scoped, bool includeInternalTypes = false) {
return RegisterValidatorsFromAssemblyContaining(typeof(T), filter, lifetime, includeInternalTypes);
}

/// <summary>
/// Registers all validators derived from AbstractValidator within the assembly containing the specified type
/// </summary>
/// <param name="type">The type that indicates which assembly that should be scanned</param>
/// <param name="filter">Optional filter that allows certain types to be skipped from registration.</param>
/// <param name="lifetime">The service lifetime that should be used for the validator registration. Defaults to Scoped</param>
/// <param name="includeInternalTypes">Include internal validators. The default is false.</param>
[Obsolete("RegisterValidatorsFromAssemblyContaining is deprecated. Call services.AddValidatorsFromAssemblyContaining instead, which has the same effect. See https://github.com/FluentValidation/FluentValidation/issues/1963")]
public FluentValidationMvcConfiguration RegisterValidatorsFromAssemblyContaining(Type type, Func<AssemblyScanner.AssemblyScanResult, bool> filter = null, ServiceLifetime lifetime = ServiceLifetime.Scoped, bool includeInternalTypes = false) {
return RegisterValidatorsFromAssembly(type.Assembly, filter, lifetime, includeInternalTypes);
}

/// <summary>
/// Registers all validators derived from AbstractValidator within the specified assembly
/// </summary>
/// <param name="assembly">The assembly to scan</param>
/// <param name="filter">Optional filter that allows certain types to be skipped from registration.</param>
/// <param name="lifetime">The service lifetime that should be used for the validator registration. Defaults to Scoped</param>
/// <param name="includeInternalTypes">Include internal validators. The default is false.</param>
[Obsolete("RegisterValidatorsFromAssembly is deprecated. Call services.AddValidatorsFromAssembly instead, which has the same effect. See https://github.com/FluentValidation/FluentValidation/issues/1963")]
public FluentValidationMvcConfiguration RegisterValidatorsFromAssembly(Assembly assembly, Func<AssemblyScanner.AssemblyScanResult, bool> filter = null, ServiceLifetime lifetime = ServiceLifetime.Scoped, bool includeInternalTypes = false) {
_services.AddValidatorsFromAssembly(assembly, lifetime, filter, includeInternalTypes);

#pragma warning disable CS0618
ValidatorFactoryType = typeof(ServiceProviderValidatorFactory);
#pragma warning restore CS0618
return this;
}

/// <summary>
/// Registers all validators derived from AbstractValidator within the specified assemblies
/// </summary>
/// <param name="assemblies">The assemblies to scan</param>
/// <param name="filter">Optional filter that allows certain types to be skipped from registration.</param>
/// <param name="lifetime">The service lifetime that should be used for the validator registration. Defaults to Scoped</param>
/// <param name="includeInternalTypes">Include internal validators. The default is false.</param>
[Obsolete("RegisterValidatorsFromAssemblies is deprecated. Call services.AddValidatorsFromAssemblies instead, which has the same effect. See https://github.com/FluentValidation/FluentValidation/issues/1963")]
public FluentValidationMvcConfiguration RegisterValidatorsFromAssemblies(IEnumerable<Assembly> assemblies, Func<AssemblyScanner.AssemblyScanResult, bool> filter = null, ServiceLifetime lifetime = ServiceLifetime.Scoped, bool includeInternalTypes = false) {
_services.AddValidatorsFromAssemblies(assemblies, lifetime, filter, includeInternalTypes);

#pragma warning disable CS0618
ValidatorFactoryType = typeof(ServiceProviderValidatorFactory);
#pragma warning restore CS0618
return this;
}

/// <summary>
/// Configures clientside validation support
/// </summary>
/// <param name="clientsideConfig"></param>
/// <param name="enabled">Whether clientside validation integration is enabled</param>
/// <returns></returns>
[Obsolete("ConfigureClientsideValidation is deprecated and will be removed in a future release. To configure client-side validation call services.AddFluentValidationClientsideAdapters(config => ...) instead. For details see https://github.com/FluentValidation/FluentValidation/issues/1965")]
public FluentValidationMvcConfiguration ConfigureClientsideValidation(Action<FluentValidationClientModelValidatorProvider> clientsideConfig=null, bool enabled=true) {
if (clientsideConfig != null) {
ClientsideConfig = clientsideConfig;
}
ClientsideEnabled = enabled;
return this;
}
}

0 comments on commit 9fd83ea

Please sign in to comment.