kmp_application/commands/
command_application_service.rs1use std::sync::Arc;
2
3use kmp_domain::{ContextEventStore, ProjectionWriter};
4
5use crate::ApplicationError;
6use crate::commands::{
7 NoopProjectionWriter, UpdateContextCommand, UpdateContextOutcome, UpdateContextUseCase,
8};
9
10#[derive(Debug)]
11pub struct CommandApplicationService<E, W = NoopProjectionWriter> {
12 update_context: Arc<UpdateContextUseCase<E, W>>,
13}
14
15impl<E, W> CommandApplicationService<E, W>
16where
17 E: ContextEventStore + Send + Sync,
18 W: ProjectionWriter + Send + Sync,
19{
20 pub fn new(update_context: Arc<UpdateContextUseCase<E, W>>) -> Self {
21 Self { update_context }
22 }
23
24 pub async fn update_context(
25 &self,
26 command: UpdateContextCommand,
27 ) -> Result<UpdateContextOutcome, ApplicationError> {
28 self.update_context.execute(command).await
29 }
30}