Struct runtime_injector::Services [−][src]
Expand description
A collection of all the providers for a particular interface.
If an interface will only have one implementation registered for it, then
it may be easier to request Svc<T>
from the container instead. However,
if multiple implementations are registered (or no implementations are
registered), then this will allow all of those implementations to be
iterated over.
An iterator over all the implementations of an interface. Each service is activated on demand.
use runtime_injector::{ interface, Injector, IntoTransient, Services, Svc, TypedProvider, }; trait Fooable: Send + Sync { fn baz(&self) {} } interface!(dyn Fooable = [Foo, Bar]); #[derive(Default)] struct Foo; impl Fooable for Foo {} #[derive(Default)] struct Bar; impl Fooable for Bar {} let mut builder = Injector::builder(); builder.provide(Foo::default.transient().with_interface::<dyn Fooable>()); builder.provide(Bar::default.transient().with_interface::<dyn Fooable>()); let injector = builder.build(); let mut counter = 0; let mut fooables: Services<dyn Fooable> = injector.get().unwrap(); for foo in fooables.get_all() { counter += 1; foo.unwrap().baz(); } assert_eq!(2, counter);
Implementations
impl<I: ?Sized + Interface> Services<I>
[src]
impl<I: ?Sized + Interface> Services<I>
[src]pub fn get_all(&mut self) -> ServicesIter<'_, I>ⓘNotable traits for ServicesIter<'a, I>
impl<'a, I: ?Sized + Interface> Iterator for ServicesIter<'a, I> type Item = InjectResult<Svc<I>>;
[src]
pub fn get_all(&mut self) -> ServicesIter<'_, I>ⓘNotable traits for ServicesIter<'a, I>
impl<'a, I: ?Sized + Interface> Iterator for ServicesIter<'a, I> type Item = InjectResult<Svc<I>>;
[src]Lazily gets all the implementations of this interface. Each service will be requested on demand rather than all at once.
pub fn get_all_owned(&mut self) -> OwnedServicesIter<'_, I>ⓘNotable traits for OwnedServicesIter<'a, I>
impl<'a, I: ?Sized + Interface> Iterator for OwnedServicesIter<'a, I> type Item = InjectResult<Box<I>>;
[src]
pub fn get_all_owned(&mut self) -> OwnedServicesIter<'_, I>ⓘNotable traits for OwnedServicesIter<'a, I>
impl<'a, I: ?Sized + Interface> Iterator for OwnedServicesIter<'a, I> type Item = InjectResult<Box<I>>;
[src]Lazily gets all the implementations of this interface as owned service pointers. Each service will be requested on demand rather than all at once. Not all providers can provide owned service pointers, so some requests may fail.
Trait Implementations
impl<I: ?Sized + Interface> Request for Services<I>
[src]
impl<I: ?Sized + Interface> Request for Services<I>
[src]Lazily requests all the implementations of an interface.
fn request(injector: &Injector, info: &RequestInfo) -> InjectResult<Self>
[src]
fn request(injector: &Injector, info: &RequestInfo) -> InjectResult<Self>
[src]Performs the request to the injector.