Closed lonix1 closed 3 years ago
Can this library work if I'm using FluentValidation
instead of FluentValidation.AspNetCore
?
Can you create simple repro with Mediatr?
Main class FluentValidationRules
uses DI for its dependencies. Try to register IValidatorFactory
for example HttpContextServiceProviderValidatorFactory
or standard ServiceProviderValidatorFactory
Thanks!!! Please tell me if I understand correctly?
FluentValidation.AspNetCore
library, it automatically registers ServiceProviderValidatorFactory
as implementation of IValidatorFactory
FluentValidation.DependencyInjectionExtensions
library, that is not registeredservices.TryAddTransient<IValidatorFactory, ServiceProviderValidatorFactory>();
services.AddFluentValidationRulesToSwagger();
If correct, it would be a good idea to add it to docs ("Common problems and workarounds").
Yes you are right. It would be great if you make PR for that! ;)
@petriashev Ok see latest PR when you get a chance
When using this workaround, I am getting the following warning: CS0618: Interface 'FluentValidation.IValidatorFactory' is obsolete
. Is this a known issue?
When using this workaround, I am getting the following warning:
CS0618: Interface 'FluentValidation.IValidatorFactory' is obsolete
. Is this a known issue?
Yes, IValidatorFactory
is obsolete. But it's not needed in latest version of package
What version is the "latest"? I am using Microelements.Swashbuckle.FluentValidation version 5.7.0 with FluentValidation.AspNetCore version 11.2.2 and get the message "ValidatorFactory is not provided. Please register FluentValidation." if I don't call services.TryAddTransient<IValidatorFactory, ServiceProviderValidatorFactory>();
.
@CollinAlpert Try 6.0.0-beta.1
Thanks so much, that fixed it!
Hello @petriashev, thanks for this great library! I've been using it for a while.
I am now using FluentValidation inside a Mediatr pipeline. So now I reference
FluentValidation
instead ofFluentValidation.AspNetCore
(otherwise I will get double validation, once by MVC and once inside Mediatr).Of course that causes this warning:
And of course the validation details are not shown in Swagger.
However I am still using FluentValdation, just in a different way. My validator classes are still the same. The container still has registrations for all the validators.
How can I make this work?