Closed diogonborges closed 3 years ago
My suggestion would be:
services.AddOpenApiDocument((settings, serviceProvider) =>
{
var fluentValidationSchemaProcessor = serviceProvider.CreateScope().ServiceProvider.GetService<FluentValidationSchemaProcessor>();
// Add the fluent validations schema processor
settings.SchemaProcessors.Add(fluentValidationSchemaProcessor);
});
// Add the FluentValidationSchemaProcessor as a singleton
services.AddScoped<FluentValidationSchemaProcessor>();
Yes, I'll get the readme updated as soon as I can test it. It should work fine as a scoped service.
It looks like there are breaking changes to FluentValidation 10 that marks some of the classes such as PropertyRule as internal. It will take a bit more time to find an alternative method to make this library compatible.
I've updated the library to support FluentValidation 10, it's released as 0.5.0-alpha0005 on NuGet. Give it a try and let me know if there are any issues. I'll publish the 0.5.0 release if everything checks out. It appears to be working on my end, but there could be cases that were not handled completely as the changes required from FluentValidation 9 to 10 internally was pretty drastic.
Thank you, we will give this a test. What sort of changes should we be aware of when consuming this library after the change to use FluentValidation v10?
@geoffreytran @vai we were using happy path straight from the Readme. The the basic usage needed some changes? I.e. the example from the Readme is updated on the alpha? Sorry I still didn't check it!
I just integrated the alpha version and everything seems to be working properly. We got the same results as when we were using the previous versions of FluentValidation, but @geoffreytran can you please let us know what sort of changes should we be aware of?
@geoffreytran This seems good - Diogo's off on leave - I can tell you we've tested the change and it's working, and now just need a release version.
In terms of changes, there were not any new functionality changes, but due to the removal of access to the following classes in v10 Upgrading to V10 I had to adjust how we access the validators. Readme has been updated with the minor change to use scoped services.
RuleBuilder PropertyRule CollectionPropertyRule IncludeRule
Changeset for V10 support https://github.com/zymlabs/nswag-fluentvalidation/commit/c236a4eeb9e7296dac91c5a071e45c3683c2765f
The majority of the changes are surrounding accessing the validation property rules and include rules. Unit tests passed, but I would be on the lookout for any edge case issues on matching of the property rules if you have custom property validators or uncommon validations. I'll publish the release if there aren't any issues found.
Our test suites were successful too. I'll advise through new issues if there's anything further from the v10 upgrade, so please feel free to close this one. Thanks for the support.
Thank you for the feedback. The release has been pushed.
Great stuff everybody. Next time,with time, I'll contribute with actual code,instead of only pointing out an issue! ;)
Great stuff everybody! Sorry I've been away and couldn't catch up sooner on this topic!
This library and its setup on readme does not currently startup the API.
The root cause of this is that Fluent now registers the IValidator as a Scoped service instead of a Transient making a Singleton Singleton FluentValidationSchemaProcessor impossible to be registered.
ZymLabs.NSwag.FluentValidation.FluentValidationSchemaProcessor': Cannot consume scoped service 'FluentValidation.IValidatorFactory' from singleton 'ZymLabs.NSwag.FluentValidation.FluentValidationSchemaProcessor'.