use crate::event::Event;
use crate::Aggregate;
use crate::CommandExecutorError;
use crate::{event::*, message::Dispatch, Application};
use actix::SystemService;
mod consistency;
mod metadata;
pub use consistency::Consistency;
pub use metadata::CommandMetadatas;
pub trait Command: std::fmt::Debug + Send + 'static {
type Event: Event + event_store::Event;
type Executor: CommandExecutor<Self> + EventApplier<Self::Event>;
type ExecutorRegistry: SystemService;
fn identifier(&self) -> String;
}
#[doc(hidden)]
#[async_trait::async_trait]
pub trait Dispatchable<C, A>
where
C: Command,
A: Application,
{
async fn dispatch(&self, cmd: C) -> Result<Vec<C::Event>, CommandExecutorError>
where
<C as Command>::ExecutorRegistry: actix::Handler<Dispatch<C, A>>;
}
pub trait CommandHandler<C: Command + ?Sized> {
fn execute(command: C, executor: &C::Executor) -> Result<Vec<C::Event>, CommandExecutorError>;
}
pub trait CommandExecutor<T: Command + ?Sized>: Aggregate {
fn execute(cmd: T, state: &Self) -> Result<Vec<T::Event>, CommandExecutorError>;
}