Skip to content

Commit 0d3d98d

Browse files
authored
Merge pull request #44 from SharpGrip/34-improve-fluentvalidation-di-setup-documentation-in-readme
improve and clarify the validator registration documentation
2 parents 21c66e4 + f13fc11 commit 0d3d98d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,27 @@ This library re-introduces this functionality for MVC controllers and introduces
1818

1919
## Installation
2020

21-
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.
21+
### Validator registration
22+
23+
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.
24+
25+
#### Manual registration
26+
27+
Manually register your validator with the service container:
28+
29+
```
30+
services.AddScoped<IValidator<User>, UserValidator>();
31+
```
32+
33+
#### Automatic registration
34+
35+
Automatically register all validators from the assembly containing your UserValidator:
36+
37+
```
38+
services.AddValidatorsFromAssemblyContaining<UserValidator>();
39+
```
40+
41+
For more instructions on setting that up please see https://docs.fluentvalidation.net/en/latest/di.html.
2242

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

0 commit comments

Comments
 (0)