injectium-salvo

Salvo integration for Injectium dependency injection.
Installation
cargo add injectium-salvo
Quick Start
use std::sync::Arc;
use injectium::{Injectable, cloned, container};
use injectium_salvo::{Injected, inject_container};
use salvo::prelude::*;
#[derive(Clone, Injectable)]
struct DbService {
connection_string: String,
}
#[derive(Injectable)]
struct UserService {
db: DbService,
}
let container = Arc::new(container! {
providers: [
cloned(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