pub struct AppContext { /* private fields */ }Expand description
A cheap, cloneable handle to a booted app.
Implementations§
Source§impl AppContext
impl AppContext
Sourcepub fn downgrade(&self) -> WeakAppContext
pub fn downgrade(&self) -> WeakAppContext
A handle that does not keep the app alive. Providers that need the
app after boot (an event bus, a scheduler) hold this instead of an
AppContext, so an app dropped without shutdown is still freed.
Sourcepub async fn get<T: ?Sized + Send + Sync + 'static>(
&self,
) -> Result<Arc<T>, KernelError>
pub async fn get<T: ?Sized + Send + Sync + 'static>( &self, ) -> Result<Arc<T>, KernelError>
Service locator: resolves the unnamed provider of T from any module,
ignoring visibility. Meant for lifecycle hooks, commands and glue code;
providers use constructor injection instead.
Sourcepub async fn try_get<T: ?Sized + Send + Sync + 'static>(&self) -> Option<Arc<T>>
pub async fn try_get<T: ?Sized + Send + Sync + 'static>(&self) -> Option<Arc<T>>
Like get, but None when no provider of T exists
(or it cannot be built; that failure is logged).
Sourcepub async fn get_named<T: ?Sized + Send + Sync + 'static>(
&self,
name: &str,
) -> Result<Arc<T>, KernelError>
pub async fn get_named<T: ?Sized + Send + Sync + 'static>( &self, name: &str, ) -> Result<Arc<T>, KernelError>
Service locator for the provider of T registered under name.
Sourcepub async fn get_all<T: ?Sized + Send + Sync + 'static>(
&self,
) -> Result<Vec<Arc<T>>, KernelError>
pub async fn get_all<T: ?Sized + Send + Sync + 'static>( &self, ) -> Result<Vec<Arc<T>>, KernelError>
Resolves every multi-binding of T (see ModuleBuilder::multi),
in module dependency order.
Sourcepub fn multi_count<T: ?Sized + 'static>(&self) -> usize
pub fn multi_count<T: ?Sized + 'static>(&self) -> usize
How many multi-bindings of T the app registers, read from the
module graph without resolving any (so a provider’s factory can call
it even when those multi-bindings depend on the provider). A module
decides with it, once at boot, whether anybody listens: navree-db
skips preparing change events in an app with no dyn ChangeObserver.
Sourcepub fn contributions<C: Send + Sync + 'static>(&self) -> Vec<Contributed<C>>
pub fn contributions<C: Send + Sync + 'static>(&self) -> Vec<Contributed<C>>
Every value of type C contributed by any module, modules in dependency
order, then in registration order.
Sourcepub fn resolver_for(&self, module: ModuleId) -> Resolver
pub fn resolver_for(&self, module: ModuleId) -> Resolver
A resolver with the visibility of module (no request scope).
Sourcepub fn request_resolver(
&self,
module: ModuleId,
scope: RequestScope,
) -> Resolver
pub fn request_resolver( &self, module: ModuleId, scope: RequestScope, ) -> Resolver
A resolver with the visibility of module that memoizes request-scoped
providers in scope (one scope per HTTP request, job run, command, …).
Sourcepub fn commands(&self) -> Vec<CommandSpec>
pub fn commands(&self) -> Vec<CommandSpec>
Every registered command, modules in dependency order.
Sourcepub fn command(&self) -> Option<&CommandSpec>
pub fn command(&self) -> Option<&CommandSpec>
The command this app was booted to run by
AppBuilder::run_with_args (or AppBuilder::run), known from
the first provider built on; None after a plain
boot. Providers check
CommandSpec::stdio here before writing to standard output.
Sourcepub fn modules(&self) -> Vec<ModuleInfo>
pub fn modules(&self) -> Vec<ModuleInfo>
Every module of the app in dependency order (imports first).
Sourcepub fn shutdown_token(&self) -> CancellationToken
pub fn shutdown_token(&self) -> CancellationToken
Cancelled when the app shuts down; long-running tasks should watch it.
Sourcepub fn tracker(&self) -> TaskTracker
pub fn tracker(&self) -> TaskTracker
Spawn background tasks here; graceful shutdown waits for them.