a3s_boot/module/mod.rs
1use crate::{
2 BoxFuture, ControllerDefinition, ModuleRef, ProviderDefinition, Result, RouteDefinition,
3};
4use std::sync::Arc;
5
6/// A module contributes imports, providers, controllers, and routes.
7///
8/// This is the Rust equivalent of a Nest module boundary. Modules organize the
9/// application graph; HTTP serving remains delegated to an adapter.
10pub trait Module: Send + Sync + 'static {
11 /// Stable module name used for deduplication and diagnostics.
12 fn name(&self) -> &'static str;
13
14 /// Imported modules that should be registered before this module.
15 fn imports(&self) -> Vec<Arc<dyn Module>> {
16 Vec::new()
17 }
18
19 /// Providers exported into the application container.
20 fn providers(&self) -> Result<Vec<ProviderDefinition>> {
21 Ok(Vec::new())
22 }
23
24 /// Controller route groups built with access to the provider container.
25 fn controllers(&self, _module_ref: &ModuleRef) -> Result<Vec<ControllerDefinition>> {
26 Ok(Vec::new())
27 }
28
29 /// Framework-neutral routes contributed directly by this module.
30 fn routes(&self) -> Result<Vec<RouteDefinition>> {
31 Ok(Vec::new())
32 }
33
34 /// Lifecycle hook called after imports and providers are registered.
35 fn on_module_init(&self, _module_ref: &ModuleRef) -> Result<()> {
36 Ok(())
37 }
38
39 /// Async lifecycle hook called by hosts that want startup work before serve.
40 fn on_application_bootstrap(&self, _module_ref: ModuleRef) -> BoxFuture<'static, Result<()>> {
41 Box::pin(async { Ok(()) })
42 }
43
44 /// Async lifecycle hook called by hosts that need graceful shutdown cleanup.
45 fn on_application_shutdown(&self, _module_ref: ModuleRef) -> BoxFuture<'static, Result<()>> {
46 Box::pin(async { Ok(()) })
47 }
48}