1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Root dependency-injection module and generated resource registrations.
//! Keep the xecute markers intact so CLI generators can register new modules.
use axum::Router;
use std::sync::Arc;
use xecute::{Container, InjectError, ModuleDefinition, ModuleGraph, module};
// xecute:modules
/// Root application dependency-injection boundary.
#[module(imports = [
// xecute:imports
])]
pub struct AppModule;
impl AppModule {
/// Collect documentation from each registered resource controller.
pub fn api_operations() -> Vec<xecute::ApiOperation> {
let operations = Vec::new();
// xecute:api
operations
}
/// Application module metadata, reusable by isolated test modules.
pub fn definitions() -> Vec<ModuleDefinition> {
vec![
Self::definition(),
// xecute:definitions
]
}
/// Validate and eagerly construct singleton providers before listening.
pub fn container() -> Result<Container, InjectError> {
let container = ModuleGraph::new(Self::definitions()).build()?;
container.initialize()?;
Ok(container)
}
/// Resolve controllers using the configured provider lifecycles.
pub fn router() -> Result<Router, InjectError> {
Self::router_with_container(Arc::new(Self::container()?))
}
/// Assemble the real HTTP routes with an application or isolated testing container.
pub fn router_with_container(container: Arc<Container>) -> Result<Router, InjectError> {
container.initialize()?;
let _ = &container;
let router = Router::new();
// xecute:routes
Ok(router)
}
}