Struct di::ServiceProvider
source · pub struct ServiceProvider { /* private fields */ }
Expand description
Represents a service provider.
Implementations§
source§impl ServiceProvider
impl ServiceProvider
sourcepub fn new(services: HashMap<Type, Vec<ServiceDescriptor>>) -> Self
pub fn new(services: HashMap<Type, Vec<ServiceDescriptor>>) -> Self
Initializes a new service provider.
Arguments
services
- TheServiceDescriptor
map encapsulated by the provider
sourcepub fn get_mut<T: Any + ?Sized>(&self) -> Option<RefMut<T>>
pub fn get_mut<T: Any + ?Sized>(&self) -> Option<RefMut<T>>
Gets a mutable service of the specified type.
sourcepub fn get_by_key<TKey, TSvc: Any + ?Sized>(
&self
) -> Option<KeyedRef<TKey, TSvc>>
pub fn get_by_key<TKey, TSvc: Any + ?Sized>( &self ) -> Option<KeyedRef<TKey, TSvc>>
Gets a keyed service of the specified type.
sourcepub fn get_by_key_mut<TKey, TSvc: Any + ?Sized>(
&self
) -> Option<KeyedRefMut<TKey, TSvc>>
pub fn get_by_key_mut<TKey, TSvc: Any + ?Sized>( &self ) -> Option<KeyedRefMut<TKey, TSvc>>
Gets a keyed, mutable service of the specified type.
sourcepub fn get_all<T: Any + ?Sized>(&self) -> impl Iterator<Item = Ref<T>> + '_
pub fn get_all<T: Any + ?Sized>(&self) -> impl Iterator<Item = Ref<T>> + '_
Gets all of the services of the specified type.
sourcepub fn get_all_mut<T: Any + ?Sized>(
&self
) -> impl Iterator<Item = RefMut<T>> + '_
pub fn get_all_mut<T: Any + ?Sized>( &self ) -> impl Iterator<Item = RefMut<T>> + '_
Gets all of the mutable services of the specified type.
sourcepub fn get_all_by_key<'a, TKey: 'a, TSvc>(
&'a self
) -> impl Iterator<Item = KeyedRef<TKey, TSvc>> + '_
pub fn get_all_by_key<'a, TKey: 'a, TSvc>( &'a self ) -> impl Iterator<Item = KeyedRef<TKey, TSvc>> + '_
Gets all of the services of the specified key and type.
sourcepub fn get_all_by_key_mut<'a, TKey: 'a, TSvc>(
&'a self
) -> impl Iterator<Item = KeyedRefMut<TKey, TSvc>> + '_
pub fn get_all_by_key_mut<'a, TKey: 'a, TSvc>( &'a self ) -> impl Iterator<Item = KeyedRefMut<TKey, TSvc>> + '_
Gets all of the mutable services of the specified key and type.
sourcepub fn get_required<T: Any + ?Sized>(&self) -> Ref<T>
pub fn get_required<T: Any + ?Sized>(&self) -> Ref<T>
Gets a required service of the specified type.
Panics
The requested service of type T
does not exist.
sourcepub fn get_required_mut<T: Any + ?Sized>(&self) -> RefMut<T>
pub fn get_required_mut<T: Any + ?Sized>(&self) -> RefMut<T>
Gets a required, mutable service of the specified type.
Panics
The requested service of type T
does not exist.
sourcepub fn get_required_by_key<TKey, TSvc: Any + ?Sized>(
&self
) -> KeyedRef<TKey, TSvc>
pub fn get_required_by_key<TKey, TSvc: Any + ?Sized>( &self ) -> KeyedRef<TKey, TSvc>
Gets a required keyed service of the specified type.
Panics
The requested service of type TSvc
with key TKey
does not exist.
sourcepub fn get_required_by_key_mut<TKey, TSvc: Any + ?Sized>(
&self
) -> KeyedRefMut<TKey, TSvc>
pub fn get_required_by_key_mut<TKey, TSvc: Any + ?Sized>( &self ) -> KeyedRefMut<TKey, TSvc>
Gets a required keyed service of the specified type.
Panics
The requested service of type TSvc
with key TKey
does not exist.
sourcepub fn create_scope(&self) -> Self
pub fn create_scope(&self) -> Self
Creates and returns a new service provider that is used to resolve services from a newly create scope.
Trait Implementations§
source§impl AsRef<ServiceProvider> for ScopedServiceProvider
impl AsRef<ServiceProvider> for ScopedServiceProvider
source§fn as_ref(&self) -> &ServiceProvider
fn as_ref(&self) -> &ServiceProvider
source§impl Borrow<ServiceProvider> for ScopedServiceProvider
impl Borrow<ServiceProvider> for ScopedServiceProvider
source§fn borrow(&self) -> &ServiceProvider
fn borrow(&self) -> &ServiceProvider
source§impl Clone for ServiceProvider
impl Clone for ServiceProvider
source§fn clone(&self) -> ServiceProvider
fn clone(&self) -> ServiceProvider
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more