injectium-salvo

Salvo integration for Injectium dependency injection.
Installation
cargo add injectium-salvo
Quick Start
use injectium::{container, Injectable};
use injectium_salvo::{inject_container, Injected};
use salvo::prelude::*;
use std::sync::Arc;
#[derive(Clone, Injectable)]
struct DbService {
connection_string: String,
}
#[derive(Injectable)]
struct UserService {
db: DbService,
}
let container = Arc::new(container! {
singletons: [
DbService { connection_string: "postgres://localhost".into() },
],
});
#[handler]
async fn hello_user(user: Injected<UserService>) -> String {
format!("User service DB: {}", user.db.connection_string)
}
let router = Router::new()
.hoop(inject_container(container))
.push(Router::with_path("/hello").get(hello_user));
Documentation
See docs.rs for full API documentation.
Features
oapi – Enable OpenAPI support for Injected<T> types
License
MIT. Made with ❤️ by Ray