pub trait ModuleDefinition:
Send
+ Sync
+ 'static {
// Required method
fn register(container: &Container) -> Result<()>;
// Provided methods
fn module_name() -> &'static str { ... }
fn imports() -> Vec<ModuleRef> { ... }
fn is_global() -> bool { ... }
fn exports() -> Vec<&'static str> { ... }
fn controllers() -> Vec<Router<Container>> { ... }
fn route_docs() -> Vec<RouteDocumentation> { ... }
fn on_module_init() -> Vec<LifecycleHook> ⓘ { ... }
fn on_module_destroy() -> Vec<LifecycleHook> ⓘ { ... }
fn on_application_bootstrap() -> Vec<LifecycleHook> ⓘ { ... }
fn on_application_shutdown() -> Vec<LifecycleHook> ⓘ { ... }
}Expand description
ModuleDefinition is the contract for defining a NestForge module.
Modules are the building blocks of a NestForge application. They group related controllers and providers together, making the codebase easier to manage and reason about.
The #[module] macro automatically generates implementations of this trait.
Manual implementation is possible for more control over the module setup.
§Manual Implementation Example
use nestforge::{ModuleDefinition, Container, ModuleRef};
use anyhow::Result;
struct MyModule;
impl ModuleDefinition for MyModule {
fn register(container: &Container) -> Result<()> {
// Register providers here
Ok(())
}
fn imports() -> Vec<ModuleRef> {
// List dependent modules
vec![]
}
}Required Methods§
Provided Methods§
Sourcefn module_name() -> &'static str
fn module_name() -> &'static str
The name of the module, used for debugging and error messages. By default, it uses the type name of the struct.
Sourcefn imports() -> Vec<ModuleRef>
fn imports() -> Vec<ModuleRef>
List any other modules that this module depends on. NestForge will make sure they’re initialized first.
Sourcefn exports() -> Vec<&'static str>
fn exports() -> Vec<&'static str>
List the providers that this module makes available to other modules that import it.
Sourcefn controllers() -> Vec<Router<Container>>
fn controllers() -> Vec<Router<Container>>
Returns the Axum routers for the controllers defined in this module.
Sourcefn route_docs() -> Vec<RouteDocumentation>
fn route_docs() -> Vec<RouteDocumentation>
Returns the documentation for the routes defined in this module.
Sourcefn on_module_init() -> Vec<LifecycleHook> ⓘ
fn on_module_init() -> Vec<LifecycleHook> ⓘ
A hook that runs after the module has been initialized.
Sourcefn on_module_destroy() -> Vec<LifecycleHook> ⓘ
fn on_module_destroy() -> Vec<LifecycleHook> ⓘ
A hook that runs when the module is being destroyed.
Sourcefn on_application_bootstrap() -> Vec<LifecycleHook> ⓘ
fn on_application_bootstrap() -> Vec<LifecycleHook> ⓘ
A hook that runs after the entire application has been bootstrapped.
Sourcefn on_application_shutdown() -> Vec<LifecycleHook> ⓘ
fn on_application_shutdown() -> Vec<LifecycleHook> ⓘ
A hook that runs when the application is shutting down.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.