Skip to main content

appletheia_application/command/
command_handler.rs

1use std::error::Error;
2
3use crate::command::Command;
4use crate::request_context::RequestContext;
5use crate::unit_of_work::UnitOfWork;
6use serde::Serialize;
7use serde::de::DeserializeOwned;
8
9#[allow(async_fn_in_trait)]
10pub trait CommandHandler: Send + Sync {
11    type Command: Command;
12    type Output: Serialize + DeserializeOwned + Send + 'static;
13    type Error: Error + Send + Sync + 'static;
14    type Uow: UnitOfWork;
15
16    async fn handle(
17        &self,
18        uow: &mut Self::Uow,
19        request_context: &RequestContext,
20        command: Self::Command,
21    ) -> Result<Self::Output, Self::Error>;
22}