Skip to content

Aggregates

Kevin Le Jeune edited this page Sep 8, 2016 · 2 revisions

An aggregate represents a part of your system. For example, an aggregate can be a user, a document, etc.

An aggregate is a POCO. It contains:

  • data (contained in properties)
  • reactions to an event (contained in methods)

An aggregate must be serializable, and is purely logic. It must not contain any OS-related object. It is designed to be saved in a database.

Aggregate methods can only modify the aggregate itself, and must not have any side-effect outside of the aggregate.

Declaration

An aggregate must implement the IAggregate interface and have the [Aggregate] attribute.

Example:

    [Aggregate]
    private class DummyAggregate : IAggregate
    {
        public string Id { get; set; }
        public string Value { get; set; }

        public void Modify(DummyModificationEvent @event)
        {
            this.Value = @event.Value;
        }

        public void Create(IEventInformation<DummyCreationEvent> eventInformation)
        {
            this.Id = eventInformation.Event.AggregateId;
        }
    }

Usage

Aggregates can be used in three main contexts:

  • They can be accessed by ID, in order to have access to their data
  • They can be queried through a Repository
  • They can be modified by raising an associated event.
Clone this wiki locally