Expand description
§navree-kernel
The Navree kernel: module graph, type-keyed dependency injection container,
lifecycle hooks and the command runner. Everything else in Navree is a
Module.
use navree_kernel::{Navree, Module, ModuleBuilder};
struct GreetingModule;
impl Module for GreetingModule {
fn register(&self, m: &mut ModuleBuilder) {
m.value(String::from("hello")).exports::<String>();
}
}
fn main() -> Result<(), navree_kernel::BoxError> {
Navree::app().module(GreetingModule).run()
}Rules: a module resolves its own providers, the exports of modules it
imports directly and the exports of global modules. Singletons are built
once (eagerly at boot, in module dependency order) and shared as Arc<T>.
Wiring errors (missing or private providers, cycles, scope inversions,
modules configured twice) fail the boot and name the module and the type.
The kernel has no global statics.
Structs§
- App
- A booted app. Dropping it without
shutdowncancels the shutdown token but runs no hooks. - AppBuilder
- Collects the root modules of an app, then validates, boots or runs it.
- AppContext
- A cheap, cloneable handle to a booted app.
- Boot
Errors - Every error found while booting or validating an app.
- Code
Configured - Contributed by a module that was given its options in code
(
for_root(options)), so tools can tell that the section of the configuration it would otherwise read is not read. navree-config warns when the configuration has such a section. - Command
Info - One command of a
ModuleReport. - Command
Spec - A command a module registers with
ModuleBuilder::command, run as<binary> <name> [args...]against a booted app. - Configured
Module - The configured form of module
M: whatM::for_root(options)andM::from_config()return, so a module does not repeat the wrapper that carries its id, says it is configured and hands its options toregister. - Contributed
- A value contributed with
ModuleBuilder::contributeand the module that contributed it. - Factory
- A provider definition for an
Arc<T>built by an async closure. Use it for trait objects (Factory::<dyn Mailer>::new(...)), named providers and values that need async setup. - Graph
Report - The validated module graph, as printed by
check --graph. - Lazy
- A handle to the unnamed provider of
T, resolved (with the visibility of the module that created it) on the firstgetand then cached. - Module
Builder - Collects what a module registers. Passed to
Module::register. - Module
Id - Identity of a module: its Rust type plus a readable name.
- Module
Info - A module of a booted app.
- Module
Report - One module of a
GraphReport. - Navree
- Entry point:
Navree::app().module(...).run(). - Provider
Key - Key of a provider in the container: a type plus an optional name, so
DbandDb("analytics")can coexist. - Provider
Report - One provider of a
ModuleReport. - Request
Scope - The cache of one unit of work (an HTTP request, a job run, a command, …):
request-scoped providers are built at most once per
RequestScope. Clones share the same cache. - Resolver
- Resolves providers with the visibility of one module: its own providers, the exports of the modules it imports and the exports of global modules.
- Weak
AppContext - A weak handle to a booted app (
AppContext::downgrade): it does not keep the app alive, andupgradereturnsNoneonce the app is dropped.
Enums§
- Kernel
Error - An error raised while validating the module graph, resolving a provider, running a lifecycle hook or dispatching a command.
- Scope
- How long a provided instance lives.
Traits§
- Injectable
- A type the container can construct (what
#[injectable]implements). - Into
Modules - Values accepted by
ModuleBuilder::imports: a module, a tuple of up to 16 modules, or aVec<Box<dyn Module>>. - Lifecycle
- Hooks implemented by a provider and registered with
ModuleBuilder::lifecycle. - Module
- A unit of an app: it registers providers, exports, imports, contributions,
lifecycle hooks and commands through a
ModuleBuilder.
Type Aliases§
- BoxError
- A boxed error that can cross module and task boundaries.
- BoxFuture
- A boxed,
Sendfuture (used where traits need to return futures as objects). - Command
Fn - The function behind a
CommandSpec.