Struct di::ServiceCollection
source · pub struct ServiceCollection { /* private fields */ }Expand description
Represents a service collection.
Implementations§
source§impl ServiceCollection
impl ServiceCollection
sourcepub fn remove(&mut self, index: usize) -> ServiceDescriptor
pub fn remove(&mut self, index: usize) -> ServiceDescriptor
sourcepub fn add<T: Into<ServiceDescriptor>>(&mut self, descriptor: T) -> &mut Self
pub fn add<T: Into<ServiceDescriptor>>(&mut self, descriptor: T) -> &mut Self
Adds a service using the specified service descriptor.
Arguments
descriptor- TheServiceDescriptorto register
sourcepub fn try_add<T: Into<ServiceDescriptor>>(
&mut self,
descriptor: T
) -> &mut Self
pub fn try_add<T: Into<ServiceDescriptor>>( &mut self, descriptor: T ) -> &mut Self
Adds a service using the specified service descriptor if the service has not already been registered.
Arguments
descriptor- TheServiceDescriptorto register
sourcepub fn try_add_to_all<T: Into<ServiceDescriptor>>(
&mut self,
descriptor: T
) -> &mut Self
pub fn try_add_to_all<T: Into<ServiceDescriptor>>( &mut self, descriptor: T ) -> &mut Self
Adds a service using the specified service descriptor if the service with same service and implementation type has not already been registered.
Arguments
descriptor- TheServiceDescriptorto register
sourcepub fn try_add_all(
&mut self,
descriptors: impl IntoIterator<Item = ServiceDescriptor>
) -> &mut Self
pub fn try_add_all( &mut self, descriptors: impl IntoIterator<Item = ServiceDescriptor> ) -> &mut Self
Adds the specified service descriptors if each of the services are not already registered with the same service and implementation type.
Arguments
descriptors- TheServiceDescriptorsequence to register
sourcepub fn replace<T: Into<ServiceDescriptor>>(
&mut self,
descriptor: T
) -> &mut Self
pub fn replace<T: Into<ServiceDescriptor>>( &mut self, descriptor: T ) -> &mut Self
Removes the first service descriptor with the same service type and adds the replacement.
Arguments
descriptor- The replacementServiceDescriptor
sourcepub fn try_replace<T: Into<ServiceDescriptor>>(
&mut self,
descriptor: T
) -> &mut Self
pub fn try_replace<T: Into<ServiceDescriptor>>( &mut self, descriptor: T ) -> &mut Self
Adds or replaces a service with the specified descriptor if the service has not already been registered.
Arguments
descriptor- The replacementServiceDescriptor
sourcepub fn remove_all<T: Any + ?Sized>(&mut self) -> &mut Self
pub fn remove_all<T: Any + ?Sized>(&mut self) -> &mut Self
Removes all specified descriptors of the specified type.
sourcepub fn build_provider(&self) -> Result<ServiceProvider, ValidationError>
pub fn build_provider(&self) -> Result<ServiceProvider, ValidationError>
Builds and returns a new ServiceProvider.
sourcepub fn iter(
&self
) -> impl Iterator<Item = &ServiceDescriptor> + ExactSizeIterator + DoubleEndedIterator
pub fn iter( &self ) -> impl Iterator<Item = &ServiceDescriptor> + ExactSizeIterator + DoubleEndedIterator
Gets a read-only iterator for the collection