ResolverContext

Struct ResolverContext 

Source
pub struct ResolverContext<'a> { /* private fields */ }
Expand description

Context passed to factory functions for resolving dependencies.

ResolverContext wraps a resolver (ServiceProvider or Scope) and provides the interface that factory functions use to access other services. This allows factory functions to be independent of the specific resolver type.

§Examples

use ferrous_di::{ServiceCollection, Resolver};
use std::sync::Arc;

struct Database { url: String }
struct UserService { db: Arc<Database> }

let mut services = ServiceCollection::new();
services.add_singleton(Database { 
    url: "postgres://localhost".to_string() 
});
services.add_transient_factory::<UserService, _>(|resolver| {
    // resolver is a ResolverContext that provides access to other services
    UserService {
        db: resolver.get_required::<Database>(),
    }
});

Trait Implementations§

Source§

impl<'a> Resolver for ResolverContext<'a>

Source§

fn register_disposer<T>(&self, service: Arc<T>)
where T: Dispose + 'static,

Registers a service for synchronous disposal. Read more
Source§

fn register_async_disposer<T>(&self, service: Arc<T>)
where T: AsyncDispose + 'static,

Registers a service for asynchronous disposal. Read more
Source§

fn get<T: 'static + Send + Sync>(&self) -> DiResult<Arc<T>>

Resolves a concrete service type. Read more
Source§

fn get_trait<T: ?Sized + 'static + Send + Sync>(&self) -> DiResult<Arc<T>>
where Arc<T>: 'static,

Resolves a single trait implementation. Read more
Source§

fn get_all_trait<T: ?Sized + 'static + Send + Sync>( &self, ) -> DiResult<Vec<Arc<T>>>
where Arc<T>: 'static,

Resolves all registered implementations of a trait. Read more
Source§

fn get_required<T: 'static + Send + Sync>(&self) -> Arc<T>

Resolves a concrete service type, panicking on failure. Read more
Source§

fn get_required_trait<T: ?Sized + 'static + Send + Sync>(&self) -> Arc<T>
where Arc<T>: 'static,

Resolves a trait implementation, panicking on failure. Read more
Source§

fn get_named<T: 'static + Send + Sync>( &self, name: &'static str, ) -> DiResult<Arc<T>>

Resolves a named concrete service type. Read more
Source§

fn get_named_required<T: 'static + Send + Sync>( &self, name: &'static str, ) -> Arc<T>

Resolves a named concrete service type, panicking on failure.
Source§

fn get_named_trait<T: ?Sized + 'static + Send + Sync>( &self, name: &'static str, ) -> DiResult<Arc<T>>
where Arc<T>: 'static,

Resolves a named trait implementation.
Source§

fn get_named_trait_required<T: ?Sized + 'static + Send + Sync>( &self, name: &'static str, ) -> Arc<T>
where Arc<T>: 'static,

Resolves a named trait implementation, panicking on failure.
Source§

impl<'a> ResolverCore for ResolverContext<'a>

Source§

fn resolve_any(&self, key: &Key) -> DiResult<Arc<dyn Any + Send + Sync>>

Resolves a single service using thread-local stack for circular dependency detection. Read more
Source§

fn resolve_many(&self, key: &Key) -> DiResult<Vec<Arc<dyn Any + Send + Sync>>>

Resolves all multi-bound services for a trait using circular dependency detection. Read more
Source§

fn push_sync_disposer(&self, f: Box<dyn FnOnce() + Send>)

Registers a synchronous disposal hook. Read more
Source§

fn push_async_disposer( &self, f: Box<dyn FnOnce() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send>, )

Registers an asynchronous disposal hook. Read more
Source§

fn resolve_any_internal( &self, key: &Key, ) -> DiResult<Arc<dyn Any + Send + Sync>>

Legacy internal resolve method for compatibility. Read more
Source§

fn resolve_many_internal( &self, key: &Key, ) -> DiResult<Vec<Arc<dyn Any + Send + Sync>>>

Legacy internal resolve many method for compatibility. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ResolverContext<'a>

§

impl<'a> !RefUnwindSafe for ResolverContext<'a>

§

impl<'a> Send for ResolverContext<'a>

§

impl<'a> Sync for ResolverContext<'a>

§

impl<'a> Unpin for ResolverContext<'a>

§

impl<'a> !UnwindSafe for ResolverContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.