use crate::{IOwned, IShared, Instance, ServiceContainer, Shared};
#[derive(Debug)]
pub struct Resolver<'ctn> {
ctn: &'ctn mut ServiceContainer,
}
impl<'ctn> Resolver<'ctn> {
pub(crate) fn new(ctn: &'ctn mut ServiceContainer) -> Self {
Self { ctn }
}
pub fn shared<S: ?Sized + IShared + 'static>(&mut self) -> Result<Shared<S>, S::Error> {
match self.ctn.resolve_shared::<S>() {
Ok(s) => Ok(Shared::new(s)),
Err(e) => Err(e),
}
}
pub fn owned<S: ?Sized + IOwned + 'static>(
&mut self,
params: S::Parameters,
) -> Result<S::Instance, S::Error> {
self.ctn.resolve_owned::<S>(params)
}
pub fn shared_instance<S: ?Sized + IShared + IOwned + 'static>(
&mut self,
) -> Result<Instance<S>, <S as IShared>::Error> {
match self.ctn.resolve_shared::<S>() {
Ok(s) => Ok(Instance::from_shared(s)),
Err(e) => Err(e),
}
}
pub fn owned_instance<S: ?Sized + IShared + IOwned + 'static>(
&mut self,
params: S::Parameters,
) -> Result<Instance<S>, <S as IOwned>::Error> {
match self.ctn.resolve_owned::<S>(params) {
Ok(l) => Ok(Instance::from_owned(l)),
Err(e) => Err(e)
}
}
}