FerroLocator
struct · ferroui-base · v0.5.0
struct FerroLocator
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.
Members
currentset_currentcurrent_mutableset_current_mutablenewwith_parent_scopebindbind_to_selfbind_to_self_singletonenter_scope
current
fn current() -> Rc<dyn IFerroDependencyResolver>
The resolver services are looked up in.
set_current
fn set_current(value: Rc<dyn IFerroDependencyResolver>)
current_mutable
fn current_mutable() -> Rc<FerroLocator>
The locator services are registered in.
set_current_mutable
fn set_current_mutable(value: Rc<FerroLocator>)
new
fn new() -> Self
with_parent_scope
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.
bind
fn bind<T: ?Sized + 'static>(self: &Self) -> RegistrationHelper<'_, T>
Starts the registration of the service type T, which may be a trait
object type.
bind_to_self
fn bind_to_self<T: 'static>(self: &Self, constant: Rc<T>) -> &FerroLocator
Registers constant as the service of its own type.
bind_to_self_singleton
fn bind_to_self_singleton<T: Default + 'static>(self: &Self) -> &FerroLocator
Registers a lazily created instance of T as the service of its own
type.
enter_scope
fn enter_scope() -> Rc<dyn IDisposable>
Makes a new locator, whose parent is the current resolver, the current one. Disposing the returned value, or dropping its last handle, restores the previous resolver and locator (once).
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeLocatorExtensionsClassDefaultsBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyErasedDestructorIntoEitherDefaultIFerroDependencyResolver
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.