framework_cqrs_lib/cqrs/infra/api_key/
component.rsuse crate::cqrs::core::api_key::services::api_key_service::ApiKeyService;
use crate::cqrs::core::api_key::services::impl_api_key_service::ImplApiKeyService;
use crate::cqrs::infra::api_key::dao::MongoApiKeyDAO;
use crate::cqrs::infra::api_key::dbo::ApiKeyDbo;
use crate::cqrs::infra::api_key::mongo_repository::MongoApiKeyRepository;
use crate::cqrs::infra::repositories::mongo_entity_repository::MongoEntityRepository;
use std::sync::Arc;
pub struct ApiKeyComponent {
pub service: Arc<dyn ApiKeyService>,
}
impl ApiKeyComponent {
pub async fn new(dbname: &str, aggregat_name: &str) -> Self {
let api_key_dao = Arc::new(
MongoApiKeyDAO::new(dbname, &format!("{aggregat_name}_api_key")).await
);
let api_key_repository: Arc<MongoEntityRepository<ApiKeyDbo>> = Arc::new(
MongoApiKeyRepository {
dao: api_key_dao.clone()
}
);
let api_key_service: Arc<dyn ApiKeyService> = Arc::new(ImplApiKeyService { repo: api_key_repository.clone() });
Self {
service: api_key_service
}
}
}