use std::sync::Arc;
use crate::{Config, ProviderRegistry, Result};
pub struct ConstructionContext<'a> {
registry: &'a ProviderRegistry,
config: &'a Config,
}
impl<'a> ConstructionContext<'a> {
pub fn new(registry: &'a ProviderRegistry, config: &'a Config) -> Self {
Self { registry, config }
}
#[allow(clippy::result_large_err)]
pub fn resolve<T>(&self) -> Result<Arc<T>>
where
T: Send + Sync + 'static,
{
self.registry.resolve()
}
pub const fn config(&self) -> &'a Config {
self.config
}
}
#[derive(Clone)]
pub struct ApplicationContext {
registry: Arc<ProviderRegistry>,
config: Arc<Config>,
}
impl ApplicationContext {
pub fn new(registry: ProviderRegistry, config: Config) -> Self {
Self {
registry: Arc::new(registry),
config: Arc::new(config),
}
}
#[allow(clippy::result_large_err)]
pub fn resolve<T>(&self) -> Result<Arc<T>>
where
T: Send + Sync + 'static,
{
self.registry.resolve()
}
pub fn config(&self) -> &Config {
self.config.as_ref()
}
}