[][src]Trait krill::commons::eventsourcing::Command

pub trait Command: Display {
    type Event: Event;
    type StorableDetails: WithStorableDetails;
    fn handle(&self) -> &Handle;
fn version(&self) -> Option<u64>;
fn store(&self) -> Self::StorableDetails; fn actor(&self) -> &str { ... }
fn conflicts(&self, _events: &[Self::Event]) -> bool { ... } }

Commands are used to send an intent to change an aggregate.

Think of this as the data container for your update API, plus some meta-data to ensure that the command is sent to the right instance of an Aggregate, and that concurrency issues are handled.

Associated Types

type Event: Event

Identify the type of event returned by the aggregate that uses this command. This is needed because we may need to check whether a command conflicts with recent events.

type StorableDetails: WithStorableDetails

Identify the type of storable component for this command. Commands may contain short-lived things (e.g. an Arc) or even secrets which should not be persisted.

Loading content...

Required methods

fn handle(&self) -> &Handle

Identifies the aggregate, useful when storing and retrieving the event.

fn version(&self) -> Option<u64>

The version of the aggregate that this command updates. If this command should update whatever the latest version happens to be, then use None here.

fn store(&self) -> Self::StorableDetails

Get the storable information for this command

Loading content...

Provided methods

fn actor(&self) -> &str

The actor who sent the command. Defaults to "krill" so that it is not mandatory to implement this.

fn conflicts(&self, _events: &[Self::Event]) -> bool

In case of concurrent processing of commands, the aggregate may be outdated when a command is applied. In such cases this method expects the list of events that happened since the ['affected_version'] and will return whether there is a conflict. If there is no conflict that the command may be applied again.

Note that this defaults to true, which is the safe choice when in doubt. If you choose to implement this, then you will also need to implement the ['set_affected_version'] function.

Loading content...

Implementors

impl<C: CommandDetails> Command for SentCommand<C>[src]

type Event = C::Event

type StorableDetails = C::StorableDetails

Loading content...