Trait runtime_injector::TypedProvider[][src]

pub trait TypedProvider: Provider {
    type Result: Service;
    fn provide_typed(
        &mut self,
        injector: &mut Injector
    ) -> InjectResult<Svc<Self::Result>>; }

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

type Result: Service[src]

The type of service this provider can activate.

Loading content...

Required methods

fn provide_typed(
    &mut self,
    injector: &mut Injector
) -> InjectResult<Svc<Self::Result>>
[src]

Provides an instance of the service. The Injector passed in can be used to retrieve instances of any dependencies this service has.

Loading content...

Implementors

impl<D, R, F> TypedProvider for SingletonProvider<D, R, F> where
    D: 'static,
    R: Service,
    F: ServiceFactory<D, R>, 
[src]

type Result = R

impl<D, R, F> TypedProvider for TransientProvider<D, R, F> where
    D: 'static,
    R: Service,
    F: ServiceFactory<D, R>, 
[src]

type Result = R

impl<R> TypedProvider for ConstantProvider<R> where
    R: Service
[src]

type Result = R

Loading content...