# Domain Events

Domain Events represent real-world events or facts that are relevant to the business or domain. They capture important moments in the lifecycle of domain entities, aggregates, or value objects. By modeling and raising domain events, you can decouple different parts of your domain model and improve the overall maintainability and flexibility of your application.

Key characteristics of Domain Events:

1. **Immutable**: Domain Events are usually immutable objects, meaning their state cannot be modified once created. This ensures that the event represents a specific occurrence at a particular moment.
2. **Side-effects**: Domain Events are often used to trigger side-effects in response to certain actions or state changes. These side-effects can be in the form of notifications, logging, or updates to other parts of the domain model.
3. **Loose coupling**: Raising Domain Events allows you to decouple different parts of the domain model. The entity or aggregate that raises the event doesn't need to know who will handle it, promoting a more flexible and extensible design.
4. **Event-driven** architecture: Domain Events play a significant role in event-driven architectures, where different components or services communicate through events rather than direct method calls.

{% hint style="info" %}
**Eiffel.Modelling.Abstractions** NuGet package contains base IDomainEvent interface. By using IDomainEvent interface you can define your domain events.
{% endhint %}

```csharp
/// <summary>
/// Domain event interface
/// </summary>
public interface IDomainEvent
{
    /// <summary>
    /// Unique event identifier
    /// </summary>
    public Guid Id { get; }
}
```

By using Domain Events, you can ensure that various parts of your application remain loosely coupled, making it easier to understand, extend, and maintain the domain model.\
\
\&#xNAN;*Example BookingCancelled domain event.*

```csharp
public class BookingCancelled : IDomainEvent
{
    public Guid Id { get; }

    public string BookingId { get; }

    public string CancellationReason { get; }

    public BookingCancelled(BookingId bookingId, string cancellationReason)
    {
        Id = Guid.NewGuid();
        BookingId = bookingId;
        CancellationReason = cancellationReason;
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.eiffel.dev/principles/domain-driven-design/domain-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
