Class ValueObjectModelBinder<TSelf, TValue>
Namespace: AdCodicem.ValueObjects.AspNetCore.ModelBinding
Assembly: AdCodicem.ValueObjects.AspNetCore.dll
Binds a value object from the raw text of a route segment, query string value, header or form field.
public sealed class ValueObjectModelBinder<TSelf, TValue> : IModelBinder where TSelf : struct, IValueObject<TSelf, TValue>
Type Parameters
TSelf
Value object type.
TValue
Underlying value type.
Inheritance
object ← ValueObjectModelBinder<TSelf, TValue>
Implements
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
The binder is closed over the concrete value object type, so binding costs one TryParse and nothing
else: no reflection, no TypeDescriptor lookup, and no exception on the rejection path. The violated
rule travels with the model error so that
Text that is empty or white space says no more than no text, as it does to MVC's own binder for every simple type
but
A refusal carries the English message of the rule, unless the application configured its messages through
AddValueObjects(messages => …): the message the resource holds under the key of the rule's code then takes
its place, quoting the display name of the member as {0} and the arguments the type's rules supply from
{1}. Blank text keeps the framework's message, which the application localises through MVC's own message
provider.
Constructors
ValueObjectModelBinder()
Initializes a binder that answers a refusal with the English message of the rule.
public ValueObjectModelBinder()
Methods
BindModelAsync(ModelBindingContext)
Attempts to bind a model.
public Task BindModelAsync(ModelBindingContext bindingContext)
Parameters
bindingContext ModelBindingContext
The
Returns
A
If model binding was successful, the true.
A model binder that completes successfully should set