bloom_web_core/controller_registry.rs
1use actix_web::web::ServiceConfig;
2
3/// A controller registration entry provided by the #[controller] macro.
4///
5/// This struct represents a controller that can be registered with the web server.
6/// Each controller has a name and a configuration function that sets up its routes.
7pub struct Controller {
8 pub name: &'static str,
9 pub configure: fn(&mut ServiceConfig),
10}
11
12inventory::collect!(Controller);
13
14/// Configures all registered controllers with the provided ServiceConfig.
15///
16/// This function iterates through all controllers registered via the inventory
17/// system and calls their configure function to set up their routes.
18///
19/// # Arguments
20/// * `cfg` - The ServiceConfig to configure with controller routes
21pub fn configure_all(cfg: &mut ServiceConfig) {
22 for c in inventory::iter::<Controller> {
23 (c.configure)(cfg);
24 }
25}