1use crate::infrastructure::{CommandRunner, Console, Database, FileSystem};
2use alloc::sync::Arc;
3use tokio::sync::Mutex;
4
5pub struct Context {
7 command_runner: Box<dyn CommandRunner + Send + Sync>,
8 console: Arc<Mutex<dyn Console + Send + Sync>>,
9 database: Box<dyn Database + Send + Sync>,
10 file_system: Arc<dyn FileSystem + Send + Sync>,
11}
12
13impl Context {
14 pub fn new(
16 command_runner: impl CommandRunner + Send + Sync + 'static,
17 console: Arc<Mutex<impl Console + Send + Sync + 'static>>,
18 database: impl Database + Send + Sync + 'static,
19 file_system: impl FileSystem + Send + Sync + 'static,
20 ) -> Self {
21 Self {
22 command_runner: Box::new(command_runner),
23 console,
24 file_system: Arc::new(file_system),
25 database: Box::new(database),
26 }
27 }
28
29 pub fn command_runner(&self) -> &(dyn CommandRunner + Send + Sync) {
31 &*self.command_runner
32 }
33
34 pub fn console(&self) -> &Mutex<dyn Console + Send + Sync> {
36 &self.console
37 }
38
39 pub fn database(&self) -> &(dyn Database + Send + Sync) {
41 &*self.database
42 }
43
44 pub fn file_system(&self) -> &Arc<dyn FileSystem + Send + Sync> {
46 &self.file_system
47 }
48}