Blazored / FluentValidation

A library for using FluentValidation with Blazor
https://blazored.github.io/FluentValidation/
MIT License
577 stars 83 forks source link

[Feature Request] Add option to set RootContextData #183

Open pokorsky opened 1 year ago

pokorsky commented 1 year ago

The FluentValidation allows to pass custom data as a dictionary to Validation call. It is possible by creating ValidationContext with RootContextData.

var person = new Person();
var context = new ValidationContext<Person>(person);
context.RootContextData["MyCustomData"] = "Test";
var validator = new PersonValidator();
validator.Validate(context);

The current FluentValidationValidator.Validate accepts only the options parameter. No way to pass the validation context.

I tried to build EditContext using ValidationContext but it did not work as EditContextFluentValidationExtensions.ValidateModel does not expect such an option and it always creates its own ValidationContext.

var context = new ValidationContext<Person>(person);
_editContext = new EditContext(context)

It would be great to extend API to allow to pass the ValidationContext the same way as validation options and support it in EditContextFluentValidationExtensions.ValidateModel.

Or did I miss something? Thanks

yenhanshih commented 10 months ago

There's an existing PR that seems to address this concern. This is waiting to be reviewed and merged in.

https://github.com/Blazored/FluentValidation/pull/156