8000 Add option to configure ValidationContext by Shipibo303 · Pull Request #254 · Blazored/FluentValidation · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add option to configure ValidationContext #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Shipibo303
Copy link

Description

This PR adds a new ConfigureContext parameter to FluentValidationValidator. This parameter allows users to pass an Action to modify the ValidationContext before it is passed to FluentValidation validators.
This solves the issue in #183, also addressed in #156, but instead of just allowing you to set RootContextData, it provides more robust access to ValidationContext configuration.

Why is this needed?

Currently, Blazored.FluentValidation does not provide a way to customize the ValidationContext used when validating a model. FluentValidation provides powerful context features, that Blazor users could make use of.

Why is this better than just allowing RootContextData?

  • RootContextData is static per validation execution, while ConfigureContext allows for dynamic modifications.
  • FluentValidation's ValidationContext<T> contains more than just RootContextData—it also allows setting a custom selector or defining a property chain.
  • More flexibility for complex validation scenarios where RootContextData alone would be insufficient.

Example Usage

<FluentValidationValidator ConfigureContext="@(ctx => ctx.RootContextData["UserRole"] = userRole)" />

This ensures that validators can access UserRole dynamically during validation.

Unit tests of this feature are also included in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0