pub trait Injectable:
Send
+ Sync
+ 'static {
// Required method
fn register(container: &Container) -> Result<()>;
}Expand description
Injectable is the core trait of NestForge’s dependency injection system.
The #[injectable] macro automatically implements this trait for the decorated struct.
It tells NestForge how to create an instance of a service and register it within
the global Container.
Manual implementation is possible for complex registration logic that the macro does not yet support.
§Manual Implementation Example
use nestforge::{Injectable, Container};
struct MyService;
impl Injectable for MyService {
fn register(container: &Container) -> anyhow::Result<()> {
// Registration logic goes here
container.register(MyService)?;
Ok(())
}
}Required Methods§
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.