Skip to main content

FerroLocator

Struct FerroLocator 

Source
pub struct FerroLocator { /* private fields */ }
Expand description

A scoped service registry.

Services are keyed by the TypeId of the service type, which can be a concrete type (Foo, fetched as Rc<Foo>) or a trait object type (dyn IFoo, fetched as Rc<dyn IFoo>):

ⓘ
FerroLocator::current_mutable().bind::<dyn IFoo>().to_constant(Rc::new(Foo::new()));
let foo: Option<Rc<dyn IFoo>> = FerroLocator::current().get_service::<dyn IFoo>();

Like the rest of the object model the locator is per-thread: the current locator and its registrations are only visible on the thread that made them.

Implementations§

Source§

impl FerroLocator

Source

pub fn current() -> Rc<dyn IFerroDependencyResolver>

The resolver services are looked up in.

Source

pub fn set_current(value: Rc<dyn IFerroDependencyResolver>)

Source

pub fn current_mutable() -> Rc<FerroLocator>

The locator services are registered in.

Source

pub fn set_current_mutable(value: Rc<FerroLocator>)

Source

pub fn new() -> Self

Source

pub fn with_parent_scope(parent_scope: Rc<dyn IFerroDependencyResolver>) -> Self

Creates a locator that falls back to parent_scope for services it has no registration for.

Source

pub fn bind<T: ?Sized + 'static>(&self) -> RegistrationHelper<'_, T>

Starts the registration of the service type T, which may be a trait object type.

Source

pub fn bind_to_self<T: 'static>(&self, constant: Rc<T>) -> &FerroLocator

Registers constant as the service of its own type.

Source

pub fn bind_to_self_singleton<T: Default + 'static>(&self) -> &FerroLocator

Registers a lazily created instance of T as the service of its own type.

Source

pub fn enter_scope() -> Rc<dyn IDisposable>

Makes a new locator, whose parent is the current resolver, the current one. Disposing the returned value restores the previous resolver and locator.

Trait Implementations§

Source§

impl Default for FerroLocator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl IFerroDependencyResolver for FerroLocator

Source§

fn get_service_untyped(&self, service_type: TypeId) -> Option<ServiceHandle>

Returns the service registered for service_type, as a handle whose content is Rc<TService>. Use LocatorExtensions::get_service for the typed form.

Auto Trait Implementations§

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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<R> LocatorExtensions for R

Source§

fn get_service<T: ?Sized + 'static>(&self) -> Option<Rc<T>>

Returns the service registered for T, which may be a trait object type (get_service::<dyn IFoo>() returns Option<Rc<dyn IFoo>>).
Source§

fn get_required_service_untyped(&self, service_type: TypeId) -> ServiceHandle

Returns the service registered for service_type. Read more
Source§

fn get_required_service<T: ?Sized + 'static>(&self) -> Rc<T>

Returns the service registered for T. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.