[][src]Trait cqrs_es::Aggregate

pub trait Aggregate: Default + Serialize + DeserializeOwned {
    fn aggregate_type() -> &'static str;
}

A trait that defines an Aggregate, the fundamental component in CQRS that encapsulates the state and business logic for the application. An Aggregate is always an entity along with all objects associated with it.

In DDD we require that changes are made only after loading the full Aggregate in order to ensure that the full context is understood.

#Example

use serde::{Serialize,Deserialize};
#[derive(Serialize,Deserialize)]
struct Customer {
    customer_id: String,
    name: String,
    email: String,
}

impl Aggregate for Customer {
    fn aggregate_type() -> &'static str { "customer" }
}

impl Default for Customer {fn default() -> Self {
        Customer {
            customer_id: "".to_string(),
            name: "".to_string(),
            email: "".to_string(),
        }
    }
}

Required methods

fn aggregate_type() -> &'static str

aggregate_type is a unique identifier for this aggregate

Loading content...

Implementors

Loading content...