Struct silhouette::Container
source · pub struct Container { /* private fields */ }
Expand description
The service container.
Implementations§
source§impl Container
impl Container
sourcepub fn get_instance() -> &'static RwLock<Self>
pub fn get_instance() -> &'static RwLock<Self>
Get the global instance of the container.
sourcepub fn bind<T: 'static>(
&mut self,
factory: impl Fn(&Self) -> T + 'static + Sync + Send
)
pub fn bind<T: 'static>( &mut self, factory: impl Fn(&Self) -> T + 'static + Sync + Send )
Register a binding with the container.
sourcepub fn bind_if<T: 'static>(
&mut self,
factory: impl Fn(&Self) -> T + 'static + Sync + Send
)
pub fn bind_if<T: 'static>( &mut self, factory: impl Fn(&Self) -> T + 'static + Sync + Send )
Register a binding if it hasn’t already been registered.
sourcepub fn scoped<T: 'static + Clone + Send + Sync>(
&mut self,
factory: &(impl Fn(&Self) -> T + 'static)
)
pub fn scoped<T: 'static + Clone + Send + Sync>( &mut self, factory: &(impl Fn(&Self) -> T + 'static) )
Register a scoped binding in the container.
sourcepub fn scoped_if<T: 'static + Clone + Send + Sync>(
&mut self,
factory: &(impl Fn(&Self) -> T + 'static)
)
pub fn scoped_if<T: 'static + Clone + Send + Sync>( &mut self, factory: &(impl Fn(&Self) -> T + 'static) )
Register a scoped binding if it hasn’t already been registered.
sourcepub fn singleton<T: 'static + Clone + Send + Sync>(
&mut self,
factory: &(impl Fn(&Self) -> T + 'static)
)
pub fn singleton<T: 'static + Clone + Send + Sync>( &mut self, factory: &(impl Fn(&Self) -> T + 'static) )
Register a shared binding in the container.
sourcepub fn singleton_if<T: 'static + Clone + Send + Sync>(
&mut self,
factory: &(impl Fn(&Self) -> T + 'static)
)
pub fn singleton_if<T: 'static + Clone + Send + Sync>( &mut self, factory: &(impl Fn(&Self) -> T + 'static) )
Register a shared binding if it hasn’t already been registered.
sourcepub fn resolve<T: 'static>(&self) -> Result<T, Error>
pub fn resolve<T: 'static>(&self) -> Result<T, Error>
Resolve the given type from the container.
Errors
Returns an error if the requested type cannot be found or if the requested type cannot be cast from the binding.
sourcepub fn forget_scoped_instances(&mut self)
pub fn forget_scoped_instances(&mut self)
Clear all of the scoped instances from the container.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Container
impl Send for Container
impl Sync for Container
impl Unpin for Container
impl !UnwindSafe for Container
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more