pub struct DispatchRuntime { /* private fields */ }Expand description
Provider + handler registry for one host instance.
Implementations§
Source§impl DispatchRuntime
impl DispatchRuntime
pub fn new( provider: Arc<ServiceProvider>, handler_cache: Arc<HandlerCache>, ) -> DispatchRuntime
pub fn provider(&self) -> &Arc<ServiceProvider> ⓘ
pub fn handler_cache(&self) -> &Arc<HandlerCache> ⓘ
Sourcepub async fn run<F, R>(&self, f: F) -> Rwhere
F: Future<Output = R>,
pub async fn run<F, R>(&self, f: F) -> Rwhere
F: Future<Output = R>,
Run an async block with this runtime active for the current task.
Sourcepub async fn run_in_scope<F, R>(self: &Arc<DispatchRuntime>, f: F) -> Rwhere
F: Future<Output = R>,
pub async fn run_in_scope<F, R>(self: &Arc<DispatchRuntime>, f: F) -> Rwhere
F: Future<Output = R>,
Run an async block with a fresh DI scope active.
dispatch_provider() resolves within the scope while the block runs, so
a hosted service that does dispatch_provider().get_owned::<DbContext>()
gets a context bound to this scope (transitive scoped dependencies
included), not one cached on the root provider. The scope is disposed
when the block finishes.
Hosted services are started and stopped inside this, which is what makes their scoped dependencies per-run instead of process-wide singletons.
Trait Implementations§
Source§impl Clone for DispatchRuntime
impl Clone for DispatchRuntime
Source§fn clone(&self) -> DispatchRuntime
fn clone(&self) -> DispatchRuntime
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for DispatchRuntime
impl !UnwindSafe for DispatchRuntime
impl Forget for DispatchRuntime
impl Freeze for DispatchRuntime
impl Send for DispatchRuntime
impl Sync for DispatchRuntime
impl Unpin for DispatchRuntime
impl UnsafeUnpin for DispatchRuntime
Blanket Implementations§
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