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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! Singleton storage trait — the basis for generated typed storage.
//!
//! Instead of `HashMap<TypeId, Box<dyn Any>>`, the framework generates
//! a struct with typed `OnceCell` fields. This trait provides the
//! common interface for the generated storage.
// Intentionally does NOT import `std::any::Any` or `std::any::TypeId`.
// This crate's core principle is to avoid TypeId-based dynamic resolution.
/// Trait for generated typed singleton stores.
///
/// The `#[derive(Injectable)]` macro contributes to a single generated
/// store struct that has one `OnceCell<Arc<T>>` per singleton-scoped
/// injectable type.
///
/// # Design Rationale
///
/// Traditional DI containers use `HashMap<TypeId, Box<dyn Any>>` which
/// requires:
/// - Runtime type lookup
/// - Dynamic downcasting with `Any::downcast_ref`
/// - Loss of compiler guarantees
///
/// Our generated store uses named fields with concrete types:
///
/// ```rust,ignore
/// pub struct AppSingletonStore {
/// database: OnceCell<Arc<Database>>,
/// cache: OnceCell<Arc<Cache>>,
/// }
///
/// impl AppSingletonStore {
/// pub async fn database(&self, ctx: &ResolveContext) -> Arc<Database> { ... }
/// pub async fn cache(&self, ctx: &ResolveContext) -> Arc<Cache> { ... }
/// }
/// ```
///
/// This is completely typed, zero-cost, and requires no `Any` or `TypeId`.
/// A minimal empty singleton store for containers with no singletons.
;
// ─── Type-safe scope markers ─────────────────────────────────────────────────
//
// Use these as the `scope=` argument in `#[injectable(scope=Singleton)]`.
// They are zero-sized marker types — no runtime overhead.
/// One instance per container (the default scope).
;
/// A fresh instance is created on every resolution.
;
/// One instance per request/task (reserved for future use).
;