1use crate::{
2 infrastructure::{CommandRunner, Console, Database, FileSystem},
3 path_pool::PathPool,
4};
5use alloc::sync::Arc;
6use tokio::sync::Mutex;
7
8pub struct Context {
10 command_runner: Box<dyn CommandRunner + Send + Sync>,
11 console: Arc<Mutex<dyn Console + Send + Sync>>,
12 database: Box<dyn Database + Send + Sync>,
13 file_system: Arc<dyn FileSystem + Send + Sync>,
14 path_pool: Arc<PathPool>,
15}
16
17impl Context {
18 pub fn new(
20 command_runner: impl CommandRunner + Send + Sync + 'static,
21 console: Arc<Mutex<impl Console + Send + Sync + 'static>>,
22 database: impl Database + Send + Sync + 'static,
23 file_system: impl FileSystem + Send + Sync + 'static,
24 path_pool: Arc<PathPool>,
25 ) -> Self {
26 Self {
27 command_runner: Box::new(command_runner),
28 console,
29 file_system: Arc::new(file_system),
30 database: Box::new(database),
31 path_pool,
32 }
33 }
34
35 pub fn command_runner(&self) -> &(dyn CommandRunner + Send + Sync) {
37 &*self.command_runner
38 }
39
40 pub fn console(&self) -> &Mutex<dyn Console + Send + Sync> {
42 &self.console
43 }
44
45 pub fn database(&self) -> &(dyn Database + Send + Sync) {
47 &*self.database
48 }
49
50 pub fn file_system(&self) -> &Arc<dyn FileSystem + Send + Sync> {
52 &self.file_system
53 }
54
55 pub fn path_pool(&self) -> &PathPool {
57 &self.path_pool
58 }
59}