Skip to content

Commit

Permalink
Merge pull request #44 from SharpGrip/34-improve-fluentvalidation-di-…
Browse files Browse the repository at this point in the history
…setup-documentation-in-readme

improve and clarify the validator registration documentation
  • Loading branch information
mvdgun authored Dec 4, 2024
2 parents 21c66e4 + f13fc11 commit 0d3d98d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,27 @@ This library re-introduces this functionality for MVC controllers and introduces

## Installation

Register your validators with the Microsoft DI service container, for instructions on setting that up please see https://docs.fluentvalidation.net/en/latest/di.html.
### Validator registration

To enable this library to automatically resolve and invoke validators for your models, you must register your validators with the Dependency Injection (DI) service container.

#### Manual registration

Manually register your validator with the service container:

```
services.AddScoped<IValidator<User>, UserValidator>();
```

#### Automatic registration

Automatically register all validators from the assembly containing your UserValidator:

```
services.AddValidatorsFromAssemblyContaining<UserValidator>();
```

For more instructions on setting that up please see https://docs.fluentvalidation.net/en/latest/di.html.

### MVC controllers [![NuGet](https://img.shields.io/nuget/v/SharpGrip.FluentValidation.AutoValidation.Mvc)](https://www.nuget.org/packages/SharpGrip.FluentValidation.AutoValidation.Mvc)

Expand Down

0 comments on commit 0d3d98d

Please sign in to comment.