Class Handlers

Intercepts the moment a whole entity is read from or written to the database, for validation or side effects at the model level.

What it is

A class handler sits around the serialization boundary of an entity model: Get() runs right after a row is deserialized into an object, and Set() runs right before that object is pushed to the database. It’s the entity-level counterpart to a property handler.

Implementing one

public class PersonClassHandler : IClassHandler<Person>
{
    public Person Get(Person entity, ClassHandlerGetOptions options) => entity;
    public Person Set(Person entity, ClassHandlerSetOptions options) => entity;
}

Mapping it to a class

Attach it with the [ClassHandler] attribute, through ClassHandlerMapper.Add<Person, PersonClassHandler>(), or fluently via FluentMapper.Entity<Person>().ClassHandler<PersonClassHandler>() — pick whichever keeps the mapping closest to where the rest of your entity’s configuration lives.