Skip to content

Announcement: Changes to ASP.NET Integration registration methods (AddFluentValidation()) #1965

@JeremySkinner

Description

@JeremySkinner

Background

The AddFluentValidation method currently enables both auto-validation and clientside integration. This method is being deprecated in favour of two replacements to allow finer control of which features are enabled:

  • AddFluentValidationAutoValidation
  • AddFluentValidationClientsideAdapters

Migration

If you were previously calling any of the following methods:

  • services.AddMvc().AddFluentValidation()
  • services.AddMvcCore().AddFluentValidation()
  • services.AddFluentValidation()

...you should now instead call:

services.AddFluentValidationAutoValidation();
services.AddFluentValidationClientsideAdapters()

If you were previously using one of the service registration methods as part of your call to AddFluentValidation then you will need to call the corresponding AddValidators… method too:

// Before 
services.AddFluentValidation(options => {
  options.RegisterValidatorsFromAssemblyContaining<MyValidator>();
});

// After migration:
services.AddFluentValidationAutoValidation();
services.AddFluentValidationClientsideAdapters();
services.AddValidatorsFromAssemblyContaining<MyValidator>();

If you were previously disabling either auto-validation or clientside validation, now you should just remove the feature you no longer need.

// Before: Enabling auto-validation and disabling clientside validation
services.AddFluentValidation(config => 
{
  config.ConfigureClientsideValidation(enabled: false);
});

// After: Enabling auto-validation only
services.AddFluentValidationAutoValidation();
// Before: Disabling auto-validation and leaving clientside validation enabled:
services.AddFluentValidation(config => 
{
  config.AutomaticValidationEnabled = false;
});

// After: Enabling client validation only:
services.AddFluentValidationClientsideAdapters();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions