Skip to main content

Module

Trait Module 

Source
pub trait Module {
    // Provided methods
    fn register_controllers(controllers: &ControllerRegistry) { ... }
    fn register_components(components: &ComponentRegistry) { ... }
    async fn register_providers(config: &Config, providers: &ProviderRegistry) { ... }
}
Expand description

A trait for defining modules in the application.

Module represents a cohesive unit of functionality that can be plugged into the application. Modules can register controllers, components, and providers to extend the application’s capabilities.

§Example

use sword_core::Module;
use sword_core::ControllerRegistry;

pub struct MyModule;

impl Module for MyModule {
    fn register_controllers(controllers: &ControllerRegistry) {
        controllers.register::<MyController>();  // Register HTTP controller
    }

    fn register_components(components: &ComponentRegistry) {
        components.register::<MyService>();
    }

    async fn register_providers(_: &Config, providers: &ProviderRegistry) {
        providers.register(MyProvider::new().await);
    }
}

Provided Methods§

Source

fn register_controllers(controllers: &ControllerRegistry)

Register controllers provided by the module. A Controller is a way to represent entry points into the application, such as HTTP controllers, Socket.IO Handlers, or gRPC services.

Source

fn register_components(components: &ComponentRegistry)

Register component structs marked with #[injectable]

Source

async fn register_providers(config: &Config, providers: &ProviderRegistry)

Register provider structs marked with #[injectable(provider)]

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§