Expand description
Controller Type Registry for runtime controller resolution
This module implements a compile-time controller type registry that enables runtime controller instantiation from string names, overcoming Rust’s type system limitations with trait object resolution.
§Architecture
ControllerTypeRegistry
: Global registry of controller factory functionsControllerFactory
: Type-erased factory function for controller creationCONTROLLER_TYPE_REGISTRY
: Thread-safe global instance
§Usage
Controllers are automatically registered via the #[controller]
macro:
#[controller("/api/users")]
pub struct UserController;
// Macro generates registration call:
// CONTROLLER_TYPE_REGISTRY.register("UserController", || Box::new(UserController::new()));
The registry then enables runtime resolution:
let controller = CONTROLLER_TYPE_REGISTRY.create_controller("UserController")?;
Structs§
- Controller
Type Registry - Thread-safe controller type registry for runtime resolution
Statics§
- CONTROLLER_
TYPE_ REGISTRY - Global controller type registry instance
Functions§
- create_
controller - Convenience function to create a controller instance
- create_
controller_ instance - Create a controller instance using Default trait
- create_
ioc_ controller_ instance - Create an IoC controller instance using IocControllable trait
- register_
controller_ type - Convenience function to register a controller type
Type Aliases§
- Controller
Factory - Type-erased factory function for creating controller instances