Skip to main content
Version: Preview (0.3.0-preview.205)

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​

IModelBinder

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 can put its stable code in the response body.

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 . An optional value object binds to null. One that cannot be null is refused as MVC refuses blank text for an , with the framework's "The value is invalid" message and , rather than reaching the action as the default instance no rule has checked.

Methods​

BindModelAsync(ModelBindingContext)​

Attempts to bind a model.

public Task BindModelAsync(ModelBindingContext bindingContext)

Parameters​

bindingContext ModelBindingContext

The .

Returns​

Task

A which will complete when the model binding process completes.

If model binding was successful, the should have set to true.

A model binder that completes successfully should set to a value returned from .