pub struct Registry { /* private fields */ }Expand description
A type-map used to register services before the application starts.
Registry is the mutable builder counterpart to AppState.
Add all services during startup, then call into_state to
produce the immutable AppState that axum holds.
Each type T can be registered at most once; a second call to add
with the same type overwrites the previous entry.
§Example
use modo::service::Registry;
let mut registry = Registry::new();
registry.add(MyService::new());
let state = registry.into_state();Implementations§
Source§impl Registry
impl Registry
Sourcepub fn add<T: Send + Sync + 'static>(&mut self, service: T)
pub fn add<T: Send + Sync + 'static>(&mut self, service: T)
Registers service under its concrete type T.
If a service of type T was already registered, it is replaced.
Sourcepub fn get<T: Send + Sync + 'static>(&self) -> Option<Arc<T>>
pub fn get<T: Send + Sync + 'static>(&self) -> Option<Arc<T>>
Returns a reference-counted handle to the service registered as type T,
or None if no such service exists.
Useful for startup validation — to confirm a required service was registered before the server begins accepting requests.
Sourcepub fn into_state(self) -> AppState
pub fn into_state(self) -> AppState
Consumes the registry and returns an AppState suitable for
passing to Router::with_state.