Skip to main content

AppContext

Struct AppContext 

Source
pub struct AppContext {
    pub event_context: EventContext,
    pub idempotency_key: Option<String>,
}
Expand description

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

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()),
};

Fields§

§event_context: EventContext

Business context: tracing identifiers, audit subject, causal lineage.

§idempotency_key: Option<String>

Optional idempotency key. When None, the upper layer or infrastructure decides whether and how to apply idempotent semantics.

Trait Implementations§

Source§

impl Clone for AppContext

Source§

fn clone(&self) -> AppContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AppContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AppContext

Source§

fn default() -> AppContext

Returns the “default value” for a type. Read more
Source§

impl From<&SerializedEvent> for AppContext

Source§

fn from(event: &SerializedEvent) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.