refactor: split bootstrap factory into per-context service builders

This commit is contained in:
2026-05-31 18:28:57 +02:00
parent c16c9d4581
commit 5a4eb1e4f8
11 changed files with 345 additions and 248 deletions

View File

@@ -0,0 +1,46 @@
use std::sync::Arc;
use adapters_postgres::{
PgPool, PostgresIngestSessionRepository, PostgresLibraryPathRepository,
PostgresQuotaRepository, PostgresStorageVolumeRepository, PostgresUsageLedgerRepository,
};
use application::storage::{CheckQuotaHandler, RegisterLibraryPathHandler, RegisterVolumeHandler};
use presentation::state::StorageHandlers;
/// Shared storage repos needed by other bounded contexts (catalog ingest, etc.).
pub struct StorageRepos {
pub volume_repo: Arc<PostgresStorageVolumeRepository>,
pub path_repo: Arc<PostgresLibraryPathRepository>,
pub session_repo: Arc<PostgresIngestSessionRepository>,
pub quota_repo: Arc<PostgresQuotaRepository>,
pub ledger_repo: Arc<PostgresUsageLedgerRepository>,
}
pub fn build(pool: &PgPool) -> (StorageRepos, StorageHandlers) {
let volume_repo = Arc::new(PostgresStorageVolumeRepository::new(pool.clone()));
let path_repo = Arc::new(PostgresLibraryPathRepository::new(pool.clone()));
let session_repo = Arc::new(PostgresIngestSessionRepository::new(pool.clone()));
let quota_repo = Arc::new(PostgresQuotaRepository::new(pool.clone()));
let ledger_repo = Arc::new(PostgresUsageLedgerRepository::new(pool.clone()));
let register_volume = Arc::new(RegisterVolumeHandler::new(volume_repo.clone()));
let register_library_path =
Arc::new(RegisterLibraryPathHandler::new(volume_repo.clone(), path_repo.clone()));
let check_quota = Arc::new(CheckQuotaHandler::new(quota_repo.clone(), ledger_repo.clone()));
let handlers = StorageHandlers {
register_volume,
register_library_path,
check_quota,
};
let repos = StorageRepos {
volume_repo,
path_repo,
session_repo,
quota_repo,
ledger_repo,
};
(repos, handlers)
}