1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! # modo::service
//!
//! Type-map service registry and axum application state.
//!
//! Provides:
//! - [`Registry`] — mutable builder used at startup to register services by type.
//! Implements [`Default`].
//! - [`AppState`] — immutable, cheaply-cloneable snapshot of the registry that axum
//! holds as its application state.
//! - [`Service<T>`](Service) — axum extractor that retrieves a registered service by
//! type from the application state.
//!
//! # Typical startup flow
//!
//! ```
//! use modo::service::{AppState, Registry};
//!
//! # struct MyDbPool;
//! # struct MyEmailClient;
//! let mut registry = Registry::new();
//! registry.add(MyDbPool);
//! registry.add(MyEmailClient);
//!
//! let state: AppState = registry.into_state();
//! let app: axum::Router = axum::Router::new()
//! .route("/", axum::routing::get(|| async { "ok" }))
//! .with_state(state);
//! ```
//!
//! Inside handlers, use the [`Service<T>`] extractor to retrieve a registered
//! service by type:
//!
//! ```
//! use modo::service::Service;
//!
//! # struct MyPool;
//! async fn handler(Service(pool): Service<MyPool>) { /* … */ }
//! ```
pub use Service;
pub use Registry;
pub use RegistrySnapshot;
pub use AppState;