pub struct Application { /* private fields */ }Expand description
The application: a Container with a boot lifecycle, an environment, and
a filesystem layout.
Implementations§
Source§impl Application
impl Application
Sourcepub fn new(base_path: impl Into<PathBuf>) -> Application
pub fn new(base_path: impl Into<PathBuf>) -> Application
A new application rooted at base_path, in the production
environment until told otherwise.
Sourcepub fn with_environment(self, environment: impl Into<String>) -> Application
pub fn with_environment(self, environment: impl Into<String>) -> Application
Builder form of set_environment.
Sourcepub fn container(&self) -> &Arc<Container> ⓘ
pub fn container(&self) -> &Arc<Container> ⓘ
The shared container. Hand this to anything that needs to resolve services without holding the whole application.
Sourcepub fn register_arc(
&self,
provider: Arc<dyn ServiceProvider>,
) -> Result<(), Error>
pub fn register_arc( &self, provider: Arc<dyn ServiceProvider>, ) -> Result<(), Error>
register for a provider that is already shared.
Sourcepub fn provider_names(&self) -> Vec<&'static str>
pub fn provider_names(&self) -> Vec<&'static str>
The names of every registered provider, in registration order.
Sourcepub async fn boot(&self) -> Result<(), Error>
pub async fn boot(&self) -> Result<(), Error>
Boot every provider that has not booted yet, running the booting
hooks first and the booted hooks after.
Idempotent, and safe to call again after registering more providers — only the new ones boot.
Sourcepub fn booting(&self, hook: impl Fn(&Application) + Send + Sync + 'static)
pub fn booting(&self, hook: impl Fn(&Application) + Send + Sync + 'static)
Run hook immediately before providers boot.
Ignored if the application has already booted — “before boot” has passed, and silently running it late would be worse than not running it.
Sourcepub fn booted(&self, hook: impl Fn(&Application) + Send + Sync + 'static)
pub fn booted(&self, hook: impl Fn(&Application) + Send + Sync + 'static)
Run hook once the application has booted — or immediately, if it
already has. The immediate call is what makes this usable from code
that cannot know whether boot has happened yet.
Sourcepub fn terminating(&self, hook: impl Fn(&Application) + Send + Sync + 'static)
pub fn terminating(&self, hook: impl Fn(&Application) + Send + Sync + 'static)
Run hook when terminate is called — after a
response has been sent, for work that should not delay it.
Sourcepub fn terminate(&self)
pub fn terminate(&self)
Run the terminating hooks. The HTTP kernel calls this after flushing
a response; a console command calls it before exiting.
Sourcepub fn environment(&self) -> String
pub fn environment(&self) -> String
The current environment name (local, testing, production, …).
Sourcepub fn set_environment(&self, environment: impl Into<String>)
pub fn set_environment(&self, environment: impl Into<String>)
Set the environment name.
Sourcepub fn environment_is(&self, names: &[&str]) -> bool
pub fn environment_is(&self, names: &[&str]) -> bool
Whether the environment is any of names.
Sourcepub fn is_testing(&self) -> bool
pub fn is_testing(&self) -> bool
Whether the environment is testing.
Sourcepub fn is_production(&self) -> bool
pub fn is_production(&self) -> bool
Whether the environment is production.
Sourcepub fn path(&self, relative: impl AsRef<Path>) -> PathBuf
pub fn path(&self, relative: impl AsRef<Path>) -> PathBuf
A path relative to the application root.
Sourcepub fn config_path(&self) -> PathBuf
pub fn config_path(&self) -> PathBuf
<base>/config.
Sourcepub fn storage_path(&self) -> PathBuf
pub fn storage_path(&self) -> PathBuf
<base>/storage.
Sourcepub fn resource_path(&self) -> PathBuf
pub fn resource_path(&self) -> PathBuf
<base>/resources — where views live.
Sourcepub fn database_path(&self) -> PathBuf
pub fn database_path(&self) -> PathBuf
<base>/database.
Methods from Deref<Target = Container>§
Sourcepub fn singleton<T, F>(&self, factory: F)
pub fn singleton<T, F>(&self, factory: F)
Bind a factory that runs once; every resolution afterwards hands
back the same Arc.
Sourcepub fn scoped<T, F>(&self, factory: F)
pub fn scoped<T, F>(&self, factory: F)
Like singleton, but flush_scoped drops the
memoised instance so the next resolution rebuilds it.
This is the binding a long-running worker wants for per-job state: the queue worker flushes scoped bindings between jobs so one job cannot leak state into the next.
Sourcepub fn instance<T>(&self, value: T)
pub fn instance<T>(&self, value: T)
Register an already-built value. The container never constructs it.
Sourcepub fn instance_arc<T>(&self, value: Arc<T>)
pub fn instance_arc<T>(&self, value: Arc<T>)
Register an already-built value that is already behind an Arc —
useful when the caller must keep a handle to it too.
Sourcepub fn resolve<T>(&self) -> Result<Arc<T>, Error>
pub fn resolve<T>(&self) -> Result<Arc<T>, Error>
Resolve T, building it if necessary.
Fails when T was never bound, when its factory fails, or when
resolving it re-enters itself (a dependency cycle).
Sourcepub fn try_resolve<T>(&self) -> Option<Arc<T>>
pub fn try_resolve<T>(&self) -> Option<Arc<T>>
Resolve T, or None if it is unbound or its factory failed.
Sourcepub fn expect_resolve<T>(&self) -> Arc<T> ⓘ
pub fn expect_resolve<T>(&self) -> Arc<T> ⓘ
Resolve T, panicking with the resolution error if it is not
available. For bootstrap code and facades, where an unbound service is
a configuration bug rather than a runtime condition.
Sourcepub fn flush_scoped(&self)
pub fn flush_scoped(&self)
Drop the memoised instance of every scoped binding.
The bindings survive; only the built values are discarded.
Trait Implementations§
Source§impl Debug for Application
impl Debug for Application
Auto Trait Implementations§
impl !Freeze for Application
impl RefUnwindSafe for Application
impl Send for Application
impl Sync for Application
impl Unpin for Application
impl UnsafeUnpin for Application
impl UnwindSafe for Application
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more