Cronus Documentation
  • Introduction
  • Getting Started
    • Quick Start
      • Setup
      • Persist First Event
      • Explore Projections
  • Cronus Framework
    • Concepts
      • Domain Driven Design
      • Event Sourcing
      • Command Query Responsibility Segregation
    • Domain Modeling
      • Bounded Context
      • Multitenancy
      • Aggregate
      • Entity
      • Value Object
      • IDs
      • Published Language
      • Messages
        • Commands
        • Events
        • Public Events
        • Signals
      • Handlers
        • Application Services
        • Sagas
        • Projections
        • Ports
        • Triggers
        • Gateways
    • Event Store
      • EventStore Player
      • Migrations
        • Copy EventStore
    • Workflows
    • Indices
    • Jobs
    • Cluster
    • Messaging
      • Serialization
    • Configuration
    • Unit testing
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Cronus Framework
  2. Domain Modeling
  3. Messages

Events

An event is something significant that has happened in the domain. It encapsulates all relevant data of the action that happened.

You can/should/must...

  • an event must be immutable

  • an event must represent a domain event that already happened with a name in the past tense

  • an event can be dispatched only by one aggregate

To create an event with Cronus, just use the IEvent markup interface.

[DataContract(Name = "728fc4e7-628b-4962-bd68-97c98aa05694")]
public class TaskCreated : IEvent
{
    TaskCreated() { }

    public TaskCreated(TaskId id, UserId userId, string name, DateTimeOffset timestamp)
    {
        Id = id;
        UserId = userId;
        Name = name;
        CreatedAt = DateTimeOffset.UtcNow;
        Timestamp = timestamp;
    }

    [DataMember(Order = 1)]
    public TaskId Id { get; private set; }

    [DataMember(Order = 2)]
    public UserId UserId { get; private set; }

    [DataMember(Order = 3)]
    public string Name { get; private set; }

    [DataMember(Order = 4)]
    public DateTimeOffset CreatedAt { get; private set; }

    [DataMember(Order = 5)]
    public DateTimeOffset Timestamp { get; private set; }

    public override string ToString()
    {
        return $"Task with id '{Id}' and name '{Name}' for user [{UserId}] at {CreatedAt} has been created.";
    }
}

Cronus uses the ToString() method for logging, so you can override it to generate user-readable logs. Otherwise, the name of the event class will be used for log messages.

PreviousCommandsNextPublic Events

Last updated 6 months ago

Was this helpful?