use crate::{
infrastructure::{CommandRunner, Console, Database, FileSystem},
path_pool::PathPool,
};
use alloc::sync::Arc;
use tokio::sync::Mutex;
pub struct Context {
command_runner: Box<dyn CommandRunner + Send + Sync>,
console: Arc<Mutex<dyn Console + Send + Sync>>,
database: Box<dyn Database + Send + Sync>,
file_system: Arc<dyn FileSystem + Send + Sync>,
path_pool: Arc<PathPool>,
}
impl Context {
pub fn new(
command_runner: impl CommandRunner + Send + Sync + 'static,
console: Arc<Mutex<impl Console + Send + Sync + 'static>>,
database: impl Database + Send + Sync + 'static,
file_system: impl FileSystem + Send + Sync + 'static,
path_pool: Arc<PathPool>,
) -> Self {
Self {
command_runner: Box::new(command_runner),
console,
file_system: Arc::new(file_system),
database: Box::new(database),
path_pool,
}
}
pub fn command_runner(&self) -> &(dyn CommandRunner + Send + Sync) {
&*self.command_runner
}
pub fn console(&self) -> &Mutex<dyn Console + Send + Sync> {
&self.console
}
pub fn database(&self) -> &(dyn Database + Send + Sync) {
&*self.database
}
pub fn file_system(&self) -> &Arc<dyn FileSystem + Send + Sync> {
&self.file_system
}
pub fn path_pool(&self) -> &PathPool {
&self.path_pool
}
}