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
//! `Provider` trait — startup-constructed application resources (A8, ADR-0004).
//!
//! A **provider** is a long-lived application resource constructed during
//! startup — a Stripe client, a search client, a signer, an external API
//! SDK. Providers are NOT constructed per request (that is the service
//! lifetime). A provider initialization failure is a typed startup failure;
//! expensive network clients are never initialized from a request
//! extractor (ADR-0004 §4).
//!
//! The `#[provider]` macro generates `impl DxComponent` (for the static
//! name used by `arc services`). The developer writes `impl Provider` by
//! hand — the `Error` type and `DEPS` are specific to the provider and
//! cannot be inferred from the struct definition alone.
//!
//! # Lifetime model
//!
//! | Lifetime | Type | When constructed | Where it lives |
//! |-----------|-----------|--------------------|--------------------|
//! | Resource | Provider | Application startup | Application state |
//! | Service | Service | Per request | Handler (via Inject)|
//! | Request | T | Per request | Handler parameter |
//!
//! Providers are placed into the application state `S` by the startup
//! closure. Services or handlers that need a provider obtain it via
//! `Resolve<S>` (the same mechanism as services) — the application
//! provides a one-line `impl Resolve<S> for MyProvider` that clones the
//! provider from state.
//!
//! # Provider init
//!
//! The developer writes a regular `async fn` constructor (not a trait
//! method) — the signature is provider-specific and may take `&Resources`,
//! `&Db`, configuration values, or any other startup input:
//!
//! ```ignore
//! impl StripeClient {
//! pub async fn init(db: &Db, config: &StripeConfig) -> Result<Self, ProviderError> {
//! // ...
//! }
//! }
//! ```
//!
//! The `Provider` trait carries `Error` (the typed init failure) and
//! `DEPS` (for `arc check` graph validation). It does NOT carry the init
//! method — init is business behavior, not mechanical plumbing, and the
//! macro must not hide business behavior (AGENTS.md, Macro design law).
use DxComponent;
/// A startup-constructed application resource (ADR-0004 §4).
///
/// Implemented by types that represent long-lived, expensive resources
/// constructed during application startup. The `#[provider]` macro
/// generates `impl DxComponent` for the name; the developer writes
/// `impl Provider` by hand with the `Error` type and `DEPS`.
///
/// Providers are NOT singletons in a container — they are plain values
/// stored in the application state. The application decides how to
/// construct, store, and share them.