1use std::sync::Arc;
4
5use crate::{Config, ProviderRegistry, Result};
6
7pub struct ConstructionContext<'a> {
9 registry: &'a ProviderRegistry,
10 config: &'a Config,
11}
12
13impl<'a> ConstructionContext<'a> {
14 pub fn new(registry: &'a ProviderRegistry, config: &'a Config) -> Self {
16 Self { registry, config }
17 }
18
19 #[allow(clippy::result_large_err)]
21 pub fn resolve<T>(&self) -> Result<Arc<T>>
22 where
23 T: Send + Sync + 'static,
24 {
25 self.registry.resolve()
26 }
27
28 pub const fn config(&self) -> &'a Config {
30 self.config
31 }
32}
33
34#[derive(Clone)]
36pub struct ApplicationContext {
37 registry: Arc<ProviderRegistry>,
38 config: Arc<Config>,
39}
40
41impl ApplicationContext {
42 pub fn new(registry: ProviderRegistry, config: Config) -> Self {
44 Self {
45 registry: Arc::new(registry),
46 config: Arc::new(config),
47 }
48 }
49
50 #[allow(clippy::result_large_err)]
52 pub fn resolve<T>(&self) -> Result<Arc<T>>
53 where
54 T: Send + Sync + 'static,
55 {
56 self.registry.resolve()
57 }
58
59 pub fn config(&self) -> &Config {
61 self.config.as_ref()
62 }
63}