Entity
An entity is an object that has an identity and is mutable. Each entity is uniquely identified by an ID rather than by its properties; therefore, two entities can be considered equal if both of them have the same ID even though they have different properties.
You can define an entity with Cronus using the Entity<TAggregateRoot, TEntityState>
base class. To publish an event from an entity, use the Apply(IEvent @event)
method provided by the base class.
Entity state
The entity state keeps current data of the entity and is responsible for changing it based on events raised only by the same entity.
Use the abstract helper class EntityState<TEntityId>
to create an entity state. It can be accessed in the entity using the state
field provided by the base class. Also, you can implement the IEntityState
interface by yourself in case inheritance is not a viable option.
To change the state of an entity, create event-handler methods for each event with a method signature public void When(Event e) { ... }
.
Entity id
Last updated
Was this helpful?