pub struct Registry<S> { /* private fields */ }Expand description
Type-erased provider registry used for service discovery and DI-style lookup.
Registration happens during bootstrap and runtime access is read-only via typed resolves.
We keep the underlying maps behind RwLock<HashMap<..>> so registration stays simple while
lookup only holds a short-lived read lock long enough to clone the stored Arc.
Implementations§
Source§impl<S: 'static> Registry<S>
impl<S: 'static> Registry<S>
Sourcepub fn insert<C>(&self, item: Arc<C>) -> &Selfwhere
C: Provider<S> + 'static,
pub fn insert<C>(&self, item: Arc<C>) -> &Selfwhere
C: Provider<S> + 'static,
Register a provider into the registry.
This accepts Arc<T> where T: Provider. The service is stored as a
type-erased Arc<dyn Provider> but continues to point to the same underlying
allocation (no new allocation is created).
If another service with the same concrete type is already registered, the new registration is skipped and a warning is logged.
Returns &Self to allow fluent chaining:
registry
.insert(dns.clone())
.insert(ipc.clone());Sourcepub fn with_typed<T, R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>where
T: Provider<S> + 'static,
pub fn with_typed<T, R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>where
T: Provider<S> + 'static,
Execute a closure with a concrete typed reference &T if the service is registered.
Sourcepub fn resolve<T>(&self) -> Option<Arc<T>>where
T: Provider<S> + 'static,
pub fn resolve<T>(&self) -> Option<Arc<T>>where
T: Provider<S> + 'static,
Resolve a concrete service as an owned Arc<T> handle.
This is the DI-style, high-level API: it returns a typed Arc<T> that
points to the same underlying allocation as the internally registered
provider (no new Arc allocation). The returned Arc is obtained by
downcasting from a type-indexed map (TypeId).
Returns None if the type is not registered.
Sourcepub fn providers(&self) -> Vec<Arc<dyn Provider<S>>>
pub fn providers(&self) -> Vec<Arc<dyn Provider<S>>>
Return a snapshot of registered providers.
Sourcepub fn list_names(&self) -> Vec<&'static str>
pub fn list_names(&self) -> Vec<&'static str>
Return the list of provider display names (for diagnostics only).
Sourcepub fn lifecycle_names(&self) -> Result<Vec<&'static str>>
pub fn lifecycle_names(&self) -> Result<Vec<&'static str>>
Return provider display names in lifecycle order.
This is useful for diagnostics and startup logging before running
boot_all().
Sourcepub fn run_all(&self, state: S, join_set: &mut JoinSet<Result<()>>) -> usize
pub fn run_all(&self, state: S, join_set: &mut JoinSet<Result<()>>) -> usize
Spawn all runnable providers into the given JoinSet.
Returns the number of tasks spawned.
Sourcepub fn validate_all(&self, state: &S) -> Result<()>
pub fn validate_all(&self, state: &S) -> Result<()>
Run validate hook for all registered providers.