Skip to main content

IRequestHandler

Trait IRequestHandler 

Source
pub trait IRequestHandler<T, R>: Send + Sync
where T: IRequest<R> + Send + 'static, R: Serialize + Send + 'static,
{ // Required method fn handle<'life0, 'async_trait>( &'life0 mut self, req: T, ) -> Pin<Box<dyn Future<Output = Result<R>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; }
Expand description

Handles a single IRequest<R>, producing its associated response R.

Authentication claims are NOT passed as a method parameter — this trait stays free of auth concerns. Instead, requests that need claims implement the inherent set_claims method (see IClaimsCarrier); the dispatcher injects claims into the request before calling handle.

Register via #[handler] proc macro for compile-time collection, or use register_handlers! for manual DI registration.

handle(&mut self, ...) enables the EFCore-style owned-DbContext pattern: handlers declare a bare ctx: DbContext field, resolved per-request via IServiceResolver::get_owned, and mutate it directly without Arc<Mutex>.

#[async_trait]
impl IRequestHandler<GetUserRequest, UserModel> for GetUserHandler {
    async fn handle(&mut self, req: GetUserRequest) -> Result<UserModel> { ... }
}

Required Methods§

Source

fn handle<'life0, 'async_trait>( &'life0 mut self, req: T, ) -> Pin<Box<dyn Future<Output = Result<R>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle the request. Claims (if any) are already in req via set_claims.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§