eventide_application/command_bus.rs
1use async_trait::async_trait;
2
3use crate::{context::AppContext, error::AppError};
4
5/// 命令总线(Command Bus)
6///
7/// - 负责根据命令的具体类型路由到对应的处理器;
8/// - 框架可提供不同实现(如进程内、消息队列等);
9/// - 该 trait 带有泛型方法,通常以具体实现类型注入使用。
10#[async_trait]
11pub trait CommandBus: Send + Sync {
12 /// 分发命令到对应处理器
13 ///
14 /// - `ctx`:应用上下文(链路追踪、幂等键等)
15 /// - `cmd`:具体命令实例
16 /// - 返回:命令处理结果
17 async fn dispatch<C, R>(&self, ctx: &AppContext, cmd: C) -> Result<R, AppError>
18 where
19 C: Send + 'static,
20 R: Send + 'static;
21}