1use super::{BootApplication, BootApplicationHandle};
2use crate::{ModuleRef, Result};
3use std::sync::Arc;
4
5pub struct BootApplicationContext {
7 pub(crate) handle: BootApplicationHandle,
8}
9
10impl BootApplicationContext {
11 pub fn app(&self) -> &BootApplication {
12 self.handle.app()
13 }
14
15 pub fn module_ref(&self) -> &ModuleRef {
16 self.handle.module_ref()
17 }
18
19 pub fn into_app(self) -> BootApplication {
20 self.handle.into_app()
21 }
22
23 pub fn get<T>(&self) -> Result<Arc<T>>
24 where
25 T: Send + Sync + 'static,
26 {
27 self.handle.get::<T>()
28 }
29
30 pub fn get_named<T>(&self, token: &str) -> Result<Arc<T>>
31 where
32 T: Send + Sync + 'static,
33 {
34 self.handle.get_named::<T>(token)
35 }
36
37 pub fn get_optional<T>(&self) -> Result<Option<Arc<T>>>
38 where
39 T: Send + Sync + 'static,
40 {
41 self.handle.get_optional::<T>()
42 }
43
44 pub fn get_optional_named<T>(&self, token: &str) -> Result<Option<Arc<T>>>
45 where
46 T: Send + Sync + 'static,
47 {
48 self.handle.get_optional_named::<T>(token)
49 }
50
51 pub fn is_initialized(&self) -> bool {
52 self.handle.is_initialized()
53 }
54
55 pub async fn init(&mut self) -> Result<()> {
56 self.handle.init().await
57 }
58
59 pub async fn close(&mut self) -> Result<()> {
60 self.handle.close().await
61 }
62
63 pub async fn close_with_signal(&mut self, signal: impl Into<String>) -> Result<()> {
64 self.handle.close_with_signal(signal).await
65 }
66}