Skip to main content

eventide_application/
command_handler.rs

1use async_trait::async_trait;
2
3use crate::{context::AppContext, error::AppError};
4
5/// 命令处理器(Command Handler)
6///
7/// - 处理具体类型的命令,执行业务用例并产生领域变化;
8/// - 建议仅做应用编排:参数校验、调用领域服务/仓储、发布事件等。
9#[async_trait]
10pub trait CommandHandler<C, R>: Send + Sync {
11    /// 处理命令,返回是否执行成功
12    async fn handle(&self, ctx: &AppContext, cmd: C) -> Result<R, AppError>;
13}