Crates.io | kti_cqrs_provider_rs |
lib.rs | kti_cqrs_provider_rs |
version | 0.3.2 |
created_at | 2023-11-05 08:14:21.889321+00 |
updated_at | 2025-08-18 10:06:19.634167+00 |
description | CQRS provider with ioc container |
homepage | https://github.com/kotletti/kti_cqrs_provider_rs |
repository | https://github.com/kotletti/kti_cqrs_provider_rs |
max_upload_size | |
id | 1025815 |
size | 18,307 |
Simple example (existed in repo)
pub struct UserController {
context: Arc<dyn ContextPort>,
}
#[async_trait]
impl AdapterPort<UserController> for UserController {
fn token() -> &'static str {
"UserController"
}
}
impl UserController {
pub fn new(context: Arc<dyn ContextPort>) -> Self {
Self { context }
}
pub async fn get_user_by_name(&self, name: &str) -> Result<Option<User>, Error> {
let bus = CqrsProvider::get_adapter(&self.context).await?;
let query = GetUserByNameQuery::new(name);
bus.query(Box::new(query)).await
}
pub async fn create_user(&self, name: &str, email: &str) -> Result<(), Error> {
let bus = CqrsProvider::get_adapter(&self.context).await?;
let command = CreateUserCommand::new(name, email);
bus.command(Box::new(command)).await?;
Ok(())
}
pub async fn create_safe_user(&self, name: &str, email: &str) -> Result<(), Error> {
let bus = CqrsProvider::get_adapter(&self.context).await?;
let command = CreateSafeUserCommand::new(name, email);
bus.command(Box::new(command)).await?;
Ok(())
}
pub async fn update_user_email(&self, name: &str, email: &str) -> Result<(), Error> {
let bus = CqrsProvider::get_adapter(&self.context).await?;
let command = UpdateUserCommand::new(name, email);
bus.command(Box::new(command)).await?;
Ok(())
}
pub async fn update_user_name(&self, current_name: &str, new_name: &str) -> Result<(), Error> {
let bus = CqrsProvider::get_adapter(&self.context).await?;
let event = RenameUserEvent::new(current_name, new_name);
bus.event(Box::new(event)).await?;
Ok(())
}
}