Module controller_registry

Module controller_registry 

Source
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 functions
  • ControllerFactory: Type-erased factory function for controller creation
  • CONTROLLER_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§

ControllerTypeRegistry
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§

ControllerFactory
Type-erased factory function for creating controller instances