Class ValidationArgsOptions
- Namespace
- Trellis.FluentValidation
- Assembly
- Trellis.FluentValidation.dll
Widens the per-validator allowlist that ValidationArgsProjection applies, so an application can publish a machine-readable operand Trellis withholds by default.
public sealed class ValidationArgsOptions
- Inheritance
-
ValidationArgsOptions
- Inherited Members
- Extension Methods
Remarks
The default allowlist is deliberately narrow: it carries only the operands whose meaning Trellis
can vouch for across every validator that populates them. FluentValidation populates
placeholders its message never uses and populates them with sentinels, so a blanket
pass-through would put maxLength: -1 on the wire for a MinimumLength failure.
Widening is therefore a per-validator decision the application makes with knowledge Trellis does
not have.
This only ever widens. There is no method to remove an entry, because the default set is the conservative one — a remove operation would only ever narrow a client contract that something already depends on, and an application that wants fewer args can stop reading them.
Widening does not bypass the safety gates. An opted-in placeholder still passes through
the containment gate, the bound, and the control-character escaping in
ValidationArgsProjection. It cannot re-admit PropertyValue or
PropertyPath: the first carries the user's submitted input verbatim, which is a
disclosure and PII hazard no opt-in should be able to switch on, and the second carries the
traversal path that the violation's own location already reports.
Register through the options system so both the standalone helpers and the Mediator pipeline adapter see the same configuration:
services.Configure<ValidationArgsOptions>(options =>
options.AllowArgs("PredicateValidator", "MinAge"));
Constructors
ValidationArgsOptions()
Initializes a new instance of the ValidationArgsOptions class.
public ValidationArgsOptions()
Properties
Default
The configuration used when an application registered none.
public static ValidationArgsOptions Default { get; }
Property Value
Remarks
This instance is shared process-wide, so it rejects AllowArgs(string, params string[]). Widening it would silently widen every validation call in the process, including those in unrelated scopes and on other threads — a global effect from what reads like a local one. Configure through the options system instead, which hands out an instance of your own.
Methods
AllowArgs(string, params string[])
Allows the named placeholders to be emitted for failures carrying
errorCode.
public ValidationArgsOptions AllowArgs(string errorCode, params string[] placeholderNames)
Parameters
errorCodestringFluentValidation's error code for the validator, such as
"PredicateValidator"or a code the application set withWithErrorCode.placeholderNamesstring[]The placeholder names as FluentValidation spells them, in
PascalCase. They reach the wire incamelCase, matching every other arg.
Returns
- ValidationArgsOptions
The same instance, so calls can be chained.
Exceptions
- ArgumentException
Thrown when
errorCodeis blank, or whenplaceholderNamesnames a placeholder that can never be allowed.- InvalidOperationException
Thrown when called on Default, which is shared process-wide.