pub struct Context<'a, D> { /* private fields */ }Expand description
The context passed to every handler.
Generic over D (the service dependency type) so handlers can access the
repository, read-model store, or custom dependencies the service is
configured with.
§Example
ⓘ
pub async fn handle(
ctx: &Context<'_, Repo>,
) -> Result<Value, HandlerError> {
let user_id = ctx.user_id()?;
let input = ctx.input::<CreateOrderInput>()?;
let repo = ctx.repo();
// ... commit via repo.commit(&mut agg).await? ...
}Implementations§
Source§impl<'a, D> Context<'a, D>
impl<'a, D> Context<'a, D>
Sourcepub fn input<T: DeserializeOwned>(&self) -> Result<T, HandlerError>
pub fn input<T: DeserializeOwned>(&self) -> Result<T, HandlerError>
Deserialize the input payload into a typed struct.
Sourcepub fn command_name(&self) -> &str
pub fn command_name(&self) -> &str
Get the command name.
Sourcepub fn message_name(&self) -> &str
pub fn message_name(&self) -> &str
Get the message name.
Sourcepub fn message(&self) -> &Message
pub fn message(&self) -> &Message
Get the full message, including id, raw payload bytes, and metadata.
Sourcepub fn user_id(&self) -> Result<&str, HandlerError>
pub fn user_id(&self) -> Result<&str, HandlerError>
Get the user ID from the session. Returns Unauthorized if not present.
Sourcepub fn dependencies(&self) -> &D
pub fn dependencies(&self) -> &D
Get a reference to the service dependencies.
Sourcepub fn repo(&self) -> &D::Repowhere
D: HasRepo,
pub fn repo(&self) -> &D::Repowhere
D: HasRepo,
Get the aggregate repository for handlers whose dependencies expose one.
Sourcepub fn read_model_store(&self) -> &D::ReadModelStorewhere
D: HasReadModelStore,
pub fn read_model_store(&self) -> &D::ReadModelStorewhere
D: HasReadModelStore,
Get the read-model store for handlers whose dependencies expose one.
Sourcepub fn has_fields(&self, fields: &[&str]) -> bool
pub fn has_fields(&self, fields: &[&str]) -> bool
Check if the raw input contains all specified fields.
Auto Trait Implementations§
impl<'a, D> Freeze for Context<'a, D>
impl<'a, D> RefUnwindSafe for Context<'a, D>where
D: RefUnwindSafe,
impl<'a, D> Send for Context<'a, D>where
D: Sync,
impl<'a, D> Sync for Context<'a, D>where
D: Sync,
impl<'a, D> Unpin for Context<'a, D>
impl<'a, D> UnsafeUnpin for Context<'a, D>
impl<'a, D> UnwindSafe for Context<'a, D>where
D: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> AggregateBuilder for T
impl<T> AggregateBuilder for T
fn aggregate<A: Aggregate>(self) -> AggregateRepository<Self, A>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Queueable for T
impl<T> Queueable for T
Source§fn queued(self) -> QueuedRepository<Self, InMemoryLockManager>
fn queued(self) -> QueuedRepository<Self, InMemoryLockManager>
Wrap with the default async lock manager. Pair with
.aggregate::<T>() for per-aggregate serialization over the async
repository surface.Source§fn queued_with<L: LockManager>(
self,
lock_manager: L,
) -> QueuedRepository<Self, L>
fn queued_with<L: LockManager>( self, lock_manager: L, ) -> QueuedRepository<Self, L>
Wrap with a custom async lock manager.