pub(crate) mod context;
pub(crate) mod layer;
use std::sync::Arc;
use crate::container::{Container, RawContainer, TypeNotRegistered};
use crate::error::{Result, TypedError};
use crate::{AppBuilder, config};
pub use context::get_app;
#[derive(Clone, Default)]
pub struct App {
pub(crate) container: RawContainer,
}
impl App {
pub fn builder() -> AppBuilder {
AppBuilder::new()
}
#[cfg(test)]
pub fn new() -> Self {
Self {
container: RawContainer::new(),
}
}
pub(crate) fn with_container(container: RawContainer) -> Self {
Self { container }
}
pub fn get<T>(&self) -> Result<Arc<T>>
where
T: 'static,
{
self.container.get::<T>()
}
pub fn config<T>(&self) -> Result<Arc<T>>
where
T: 'static + config::Config,
{
self.get::<T>().map_err(|e| {
if e.is(TypeNotRegistered) {
config::ConfigNotRegistered::error(format!(
"Configuration of type {} is not registered",
std::any::type_name::<T>()
))
} else {
e
}
})
}
}