Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectDapper

Namespace: AdCodicem.ValueObjects.Dapper
Assembly: AdCodicem.ValueObjects.Dapper.dll

Registers Dapper type handlers for value objects.

public static class ValueObjectDapper

Inheritance​

object ← ValueObjectDapper

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

Dapper keeps its handlers in a process-wide table, so this is called once at start-up. Without it, every query touching a value object would need an explicit projection.

Methods​

AddValueObjectHandler<TSelf, TValue>()​

Registers a handler for one value object, such as a construction of a generic value object.

public static void AddValueObjectHandler<TSelf, TValue>() where TSelf : struct, IValueObject<TSelf, TValue>

Type Parameters​

TSelf

Value object type, Code<Order> for instance.

TValue

Underlying value type.

Remarks​

The handler is the one registers, for the value object and its nullable form, and a value object Dapper already has a handler for keeps it. Closed at compile time, it needs no dynamic code to be built, and it reads the column the value object declares off , without asking the registry, which would describe a construction by reflection; Dapper reflects over the handlers it is given.

Exceptions​

NotSupportedException

TValue is or , which no ADO.NET provider carries.

AddValueObjectHandlers(params Assembly[])​

Registers a handler for every value object declared in the given assemblies.

[RequiresUnreferencedCode("Locates the generated registration of each assembly given by its metadata.")]
public static void AddValueObjectHandlers(params Assembly[] assemblies)

Parameters​

assemblies Assembly[]

Assemblies declaring the value objects. When none is given, everything already registered is handled.

Remarks​

A value object Dapper already has a handler for keeps it, whoever registered it, so calling this again changes nothing and a handler of the application's own is not replaced. Which types are handled is read from Dapper's table rather than remembered here, so a call after registers everything again.

A value object over or gets no handler. No ADO.NET provider takes either as a parameter or returns one, so the column type, and the conversion to it, are the application's to choose, in a handler of its own.

A generic value object has no handler until its constructions are known, and Dapper looks a handler up by the exact type, ahead of any query: register each construction with .

Each handler is closed over its value object at compile time, through the type arguments the descriptor hands back to a visitor (), never at run time with , so building them takes no dynamic code. Locating the generated registration of an assembly given by name reads its metadata, which trimming may remove. Dapper itself is not compatible with native AOT: it files each handler in a cache it closes over the type at run time, and reads rows through code it emits.