question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an extension to IServiceCollection to add all Validators in Assembly without MVC

See original GitHub issue

I’ve been looking around everywhere but can’t seem to find the Extension method on IServiceCollection. With the coming of Razor Components we don’t have controllers anymore but pages. Therefore it would be nice to have an Extension method AddValidators which looks up all the IValidators and hooks them into DI e.g.:

services.AddTransient<IValidator<CreateCustomerCommand>, CreateCustomerValidator>();

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vertonghenbcommented, Jan 29, 2019

Where will the FluentValidation.DependencyInjection package be located?

1reaction
JeremySkinnercommented, Jan 18, 2019

Hi, although there’s no extension method you can use FluentValidation’s AssemblyScanner for this already:

AssemblyScanner.FindValidatorsInAssemblyContaining<MyValidator>().ForEach(result => {
  services.AddTransient(result.InterfaceType, result.ValidatorType);
});

(This is what the MVC extension uses internally)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add an extension to IServiceCollection to add all Validators ...
I've been looking around everywhere but can't seem to find the Extension method on IServiceCollection. With the coming of Razor Components ...
Read more >
Adding Mvc options separately after adding Mvc services
I would like to write an extension method for for the IServiceCollection , which will do the configuration in the application. The reason...
Read more >
MvcCoreServiceCollectionExten...
Adds the minimum essential MVC services to the specified IServiceCollection. ... MVC's support for authorization, formatters, and validation must be added ...
Read more >
ASP.NET Core — FluentValidation documentation
Alternatively you can register all validators in a specific assembly by using our Service Collection extensions. To do this you'll need to install...
Read more >
Dependency injection in ASP.NET Core
The convention is to use a single Add{GROUP_NAME} extension method to register all of the services required by a framework feature.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found