Trait runtime_injector::TypedProvider [−][src]
A strongly-typed service provider. Types which implement this provide
instances of a service type when requested. Examples of typed providers
include providers created from service factories or constant providers.
This should be preferred over Provider
for custom service providers if
possible due to the strong type guarantees this provides. Provider
is
automatically implemented for all types which implement TypedProvider
.
Example
use runtime_injector::{TypedProvider, Injector, InjectResult, Svc}; struct Foo; struct FooProvider; impl TypedProvider for FooProvider { type Result = Foo; fn provide_typed(&mut self, _injector: &mut Injector) -> InjectResult<Svc<Self::Result>> { Ok(Svc::new(Foo)) } } let mut builder = Injector::builder(); builder.provide(FooProvider); let mut injector = builder.build(); let _foo: Svc<Foo> = injector.get().unwrap();
Associated Types
Loading content...Required methods
fn provide_typed(
&mut self,
injector: &mut Injector
) -> InjectResult<Svc<Self::Result>>
[src]
&mut self,
injector: &mut Injector
) -> InjectResult<Svc<Self::Result>>
Provides an instance of the service. The Injector
passed in can be
used to retrieve instances of any dependencies this service has.
Implementors
impl<D, R, F> TypedProvider for SingletonProvider<D, R, F> where
D: 'static,
R: Service,
F: ServiceFactory<D, R>,
[src]
D: 'static,
R: Service,
F: ServiceFactory<D, R>,
type Result = R
fn provide_typed(
&mut self,
injector: &mut Injector
) -> InjectResult<Svc<Self::Result>>
[src]
&mut self,
injector: &mut Injector
) -> InjectResult<Svc<Self::Result>>
impl<D, R, F> TypedProvider for TransientProvider<D, R, F> where
D: 'static,
R: Service,
F: ServiceFactory<D, R>,
[src]
D: 'static,
R: Service,
F: ServiceFactory<D, R>,
type Result = R
fn provide_typed(
&mut self,
injector: &mut Injector
) -> InjectResult<Svc<Self::Result>>
[src]
&mut self,
injector: &mut Injector
) -> InjectResult<Svc<Self::Result>>
impl<R> TypedProvider for ConstantProvider<R> where
R: Service,
[src]
R: Service,
type Result = R
fn provide_typed(
&mut self,
_injector: &mut Injector
) -> InjectResult<Svc<Self::Result>>
[src]
&mut self,
_injector: &mut Injector
) -> InjectResult<Svc<Self::Result>>