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
use ;
/// Application Context for a single command/query invocation.
///
/// `AppContext` carries the cross-cutting metadata required by the
/// application layer when handling one logical request. It is created at the
/// system boundary (HTTP handler, message consumer, scheduled job) and
/// passed unchanged through the command/query bus down to the handler so
/// that downstream domain events can be tagged with the correct provenance.
///
/// The context bundles two concerns:
///
/// - Business / tracing context ([`EventContext`]): correlation id, causation
/// id, and the actor (type and id) responsible for the operation. These
/// fields are persisted alongside emitted domain events so that the full
/// causal chain can be reconstructed for auditing and debugging.
/// - Idempotency key (`idempotency_key`): an optional infrastructure-level
/// token used by the API or messaging layer to deduplicate retried
/// submissions. The application/domain layers do not interpret this
/// value — they merely propagate it to the infrastructure boundary.
///
/// # Examples
///
/// ```rust
/// use eventide_application::context::AppContext;
/// use eventide_domain::domain_event::EventContext;
///
/// let ctx = AppContext {
/// event_context: EventContext::builder()
/// .maybe_correlation_id(Some("cor-123".into()))
/// .maybe_causation_id(Some("cau-abc".into()))
/// .maybe_actor_type(Some("user".into()))
/// .maybe_actor_id(Some("u-1".into()))
/// .build(),
/// idempotency_key: Some("idem-xyz".into()),
/// };
/// ```