pub trait IRequestHandler<T, R>: Send + Sync{
// Required method
fn handle<'life0, 'async_trait>(
&'life0 mut self,
req: T,
) -> Pin<Box<dyn Future<Output = ActionResult<R>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Handles a single IRequest<R>, producing its associated response R.
Authentication identity is not passed as a method parameter — this trait stays
free of auth concerns. Requests that need the caller declare
#[fromclaim] user: IdentityUser; the binder fills it before handle runs.
Register via #[handler] proc macro for compile-time collection; for
non-HTTP Mediator use, register the handler in DI with rust-dix’s
#[rust_dix::inject] attribute (trait-impl registration) or
ServiceCollection::singleton.
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) -> ActionResult<UserModel> { ... }
}Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".