Registration And Lifecycle Order
Module registration follows the metadata graph. Each module is discovered once; repeated imports share one provider graph and module-import cycles are startup errors.
- The complete module graph, exports, duplicates, and dependency metadata are validated.
- Providers are constructed in dependency order and initialized once.
- Event handlers are registered after their provider exists.
on_bootstrapruns in dependency order.
on_module_init runs when an injectable provider is registered. on_shutdown
runs once in reverse successful startup order. If startup fails, Caelix shuts
down providers already initialized and preserves the original error. Shutdown
continues after individual hook failures and returns the first such error.
Async factory providers are construction-only and use no-op lifecycle callbacks.
Controllers participate in dependency injection because registering a controller creates a provider definition for that controller type.
Visibility
Providers are visible to their declaring module, to direct importers only when explicitly exported, and through explicit exports of reachable global modules. An import does not expose a module’s private providers. Re-exporting is allowed only from a direct import.
Failures
Startup can fail for:
- Missing providers declared in module metadata.
- Missing event handler providers.
- Missing
EventModuleimport before resolvingArc<EventBus>or registering event handlers. - A dependency that is private, unexported, or declared by a module that was not imported.
- A handwritten provider or factory resolving a type absent from its declared dependencies.
- Duplicate production provider, factory, controller, or gateway registrations.
- Async factory errors.
- Lifecycle hook errors.
- Dependency resolution failures during provider construction.
Application::new::<AppModule>() returns startup errors as caelix::Result<Application>, so callers can choose whether to propagate, map, or unwrap them.