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
impl FerroLocator
Sourcepub fn current() -> Rc<dyn IFerroDependencyResolver>
pub fn current() -> Rc<dyn IFerroDependencyResolver>
The resolver services are looked up in.
pub fn set_current(value: Rc<dyn IFerroDependencyResolver>)
Sourcepub fn current_mutable() -> Rc<FerroLocator>
pub fn current_mutable() -> Rc<FerroLocator>
The locator services are registered in.
pub fn set_current_mutable(value: Rc<FerroLocator>)
pub fn new() -> Self
Sourcepub fn with_parent_scope(parent_scope: Rc<dyn IFerroDependencyResolver>) -> Self
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.
Sourcepub fn bind<T: ?Sized + 'static>(&self) -> RegistrationHelper<'_, T>
pub fn bind<T: ?Sized + 'static>(&self) -> RegistrationHelper<'_, T>
Starts the registration of the service type T, which may be a trait
object type.
Sourcepub fn bind_to_self<T: 'static>(&self, constant: Rc<T>) -> &FerroLocator
pub fn bind_to_self<T: 'static>(&self, constant: Rc<T>) -> &FerroLocator
Registers constant as the service of its own type.
Sourcepub fn bind_to_self_singleton<T: Default + 'static>(&self) -> &FerroLocator
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.
Sourcepub fn enter_scope() -> Rc<dyn IDisposable>
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
impl Default for FerroLocator
Source§impl IFerroDependencyResolver for FerroLocator
impl IFerroDependencyResolver for FerroLocator
Source§fn get_service_untyped(&self, service_type: TypeId) -> Option<ServiceHandle>
fn get_service_untyped(&self, service_type: TypeId) -> Option<ServiceHandle>
service_type, as a handle whose
content is Rc<TService>. Use
LocatorExtensions::get_service for the typed form.Auto Trait Implementations§
impl !Freeze for FerroLocator
impl !RefUnwindSafe for FerroLocator
impl !Send for FerroLocator
impl !Sync for FerroLocator
impl !UnwindSafe for FerroLocator
impl Unpin for FerroLocator
impl UnsafeUnpin for FerroLocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read moreSource§impl<R> LocatorExtensions for Rwhere
R: IFerroDependencyResolver + ?Sized,
impl<R> LocatorExtensions for Rwhere
R: IFerroDependencyResolver + ?Sized,
Source§fn get_service<T: ?Sized + 'static>(&self) -> Option<Rc<T>>
fn get_service<T: ?Sized + 'static>(&self) -> Option<Rc<T>>
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
fn get_required_service_untyped(&self, service_type: TypeId) -> ServiceHandle
service_type. Read more