#cqrs #query #command #container #provider #ioc #async

kti_cqrs_provider_rs

CQRS provider with ioc container

3 releases (breaking)

0.2.0 Mar 17, 2024
0.1.0 Mar 3, 2024
0.0.1 Nov 5, 2023

#30 in #ioc

Download history 19/week @ 2024-07-18 31/week @ 2024-07-25 43/week @ 2024-08-01 32/week @ 2024-08-08 13/week @ 2024-08-22 63/week @ 2024-08-29 16/week @ 2024-09-05 45/week @ 2024-09-12 27/week @ 2024-09-19 22/week @ 2024-09-26 7/week @ 2024-10-03 25/week @ 2024-10-10 28/week @ 2024-10-17 4/week @ 2024-10-24

61 downloads per month

MIT/Apache

7KB
127 lines

CQRS provider with ioc container

Wrapped kti_cqrs_rs via provider for more complex usage

Simple example (existed in repo)

pub struct UserController {
  context: Arc<ContainerContext>,
}

impl UserController {
  pub fn new(context: Arc<ContainerContext>) -> Self {
    Self { context }
  }

  pub fn token() -> &'static str {
    "USER_CONTROLLER"
  }

  pub async fn get_user_by_name(&self, name: &str) -> Result<Option<User>, Box<dyn Error>> {
    let bus = self.get_cqrs_bus().await;

    let query = GetUserByNameQuery::new(name);

    bus.query(Box::new(query)).await
  }

  pub async fn create_user(&self, name: &str, email: &str) -> Result<(), Box<dyn Error>> {
    let bus = self.get_cqrs_bus().await;

    let command = CreateUserCommand::new(name, email);

    bus.command(Box::new(command)).await;

    Ok(())
  }

  pub async fn update_user(&self, name: &str, email: &str) -> Result<(), Box<dyn Error>> {
    let bus = self.get_cqrs_bus().await;

    let command = UpdateUserCommand::new(name, email);

    bus.command(Box::new(command)).await;

    Ok(())
  }

  async fn get_cqrs_bus(&self) -> cqrs_provider::Provider {
    self
      .context
      .resolve_provider::<cqrs_provider::Provider>(cqrs_provider::Provider::token())
      .await
  }
}

Dependencies

~2.6–9.5MB
~74K SLoC