Table of Contents

Class ScalarValueModelBinderProvider

Namespace
Trellis.Asp.ModelBinding
Assembly
Trellis.Asp.dll

Detects scalar value types and Maybe<T> wrapping scalar value types, and provides model binders for them.

public class ScalarValueModelBinderProvider : IModelBinderProvider
Inheritance
ScalarValueModelBinderProvider
Implements
Inherited Members
Extension Methods

Examples

Registration in Program.cs:

builder.Services
    .AddControllers()
    .AddScalarValueValidation();

Remarks

This provider checks if a model type implements IScalarValue<TSelf, TPrimitive> or is Maybe<T> where T implements IScalarValue<TSelf, TPrimitive>, and creates appropriate model binders.

Register this provider using AddScalarValueValidation() extension method on IMvcBuilder.

Methods

GetBinder(ModelBinderProviderContext)

Returns a model binder for scalar value types or Maybe<T> wrapping scalar value types, or null for other types.

[UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "Value object types are preserved by model binding infrastructure")]
[UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Value object types are preserved by model binding infrastructure")]
[UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Value object types are preserved by model binding infrastructure")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Model binding is not compatible with Native AOT")]
public IModelBinder? GetBinder(ModelBinderProviderContext context)

Parameters

context ModelBinderProviderContext

The model binder provider context.

Returns

IModelBinder

A model binder for the type, or null if not applicable.

Remarks

This method uses reflection to detect value object types and create binders dynamically. It is not compatible with Native AOT scenarios.