6 releases (3 breaking)
Uses new Rust 2024
| 0.4.0 | Mar 6, 2026 |
|---|---|
| 0.3.0 | Mar 3, 2026 |
| 0.2.1 | Mar 3, 2026 |
| 0.2.0 | Feb 24, 2026 |
| 0.1.1 | Feb 24, 2026 |
#3 in #path-router
35KB
51 lines
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::*;
// Define your services
#[derive(Clone, Injectable)]
struct DbService {
connection_string: String,
}
#[derive(Injectable)]
struct UserService {
db: DbService,
}
// Build the container
let container = Arc::new(container! {
providers: [
cloned(DbService { connection_string: "postgres://localhost".into() }),
],
});
// Handler with dependency injection
#[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 forInjected<T>types
License
Dependencies
~22–35MB
~656K SLoC