Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Announcement: Deprecation of RegisterValidator... methods within calls to AddFluentValidation #1963

Closed
JeremySkinner opened this issue Jun 18, 2022 · 0 comments

Comments

@JeremySkinner
Copy link
Member

JeremySkinner commented Jun 18, 2022

Background

We currently provide 2 ways of registering validators with the ASP.NET service provider:

  • Within calls to AddFluentValidation()
  • With extension methods on the IServiceCollection

Both approaches do exactly the same thing. We will be deprecating the older approach (via AddFluentValidation) in favour of the extension method approach

Migration Steps

If you were previously calling one of the RegisterValidators... methods inside AddFluentValidation() you should migrate to calling the equivalent RegisterValidators... extension method:

Before:

public void ConfigureServices(IServiceCollection services) 
{
   // ... other configuration ...
 
  services.AddFluentValidation(config => 
  {
     config.RegisterValidatorsFromAssemblyContaining<SomeValidator>();
     // or
     config.RegisterValidatorsFromAssemblyContaining(typeof(SomeValidator));
     // or
     config.RegisterValidatorsFromAssembly(typeof(SomeValidator).Assembly);
   });
}

After:

public void ConfigureServices(IServiceCollection services) 
{
   // ... other configuration ...

   services.AddFluentValidationAutoValidation();
   services.AddFluentValidationClientsideAdapters();

   services.AddValidatorsFromAssemblyContaining<SomeValidator>();
   // or
   services.AddValidatorsFromAssemblyContaining(typeof(SomeValidator));
   // or
   services.AddValidatorsFromAssembly(typeof(SomeValidator).Assembly);
}
@FluentValidation FluentValidation locked as resolved and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant