Expand description
§More DI for Axum

More DI is a dependency injection (DI) library for Rust. This library provides additional DI extensions for the axum web framework.
You may be looking for:
§Dependency Injection in Axum
Consider the following Person structure which can be composed into a web application:
use axum::{routing::get, Router};
use di::{injectable, Injectable, ServiceCollection};
use di_axum::{prelude::*, Inject};
use tokio::net::TcpListener;
#[injectable]
struct Person;
impl Person {
fn speak(&self) -> &str {
"Hello world!"
}
}
async fn say_hello(Inject(person): Inject<Person>) -> String {
person.speak().to_owned()
}
#[tokio::main]
async fn main() {
let provider = ServiceCollection::new()
.add(Person::scoped())
.build_provider()
.unwrap();
let app = Router::new()
.route("/hello", get(say_hello))
.with_provider(provider);
let listener = TcpListener::bind("127.0.0.1:5000").await.unwrap();
println!("Now listening on: {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();
}§License
This project is licensed under the MIT license.
Modules§
- prelude
- Contains library prelude.
Structs§
- Inject
- Represents a container for a required, injected service.
- Inject
All - Represents a container for a collection of injected services.
- Inject
AllMut - Represents a container for a collection of mutable, injected services.
- Inject
AllWith Key - Represents a container for a collection of injected, keyed services.
- Inject
AllWith KeyMut - Represents a container for a collection of mutable, injected, keyed services.
- Inject
Mut - Represents a container for a required, mutable, injected service.
- Inject
With Key - Represents a container for a required, injected, keyed service.
- Inject
With KeyMut - Represents a container for a required, mutable, injected, keyed service.
- TryInject
- Represents a container for an optional, injected service.
- TryInject
Mut - Represents a container for an optional, mutable, injected service.
- TryInject
With Key - Represents a container for an optional, injected, keyed service.
- TryInject
With KeyMut - Represents a container for an optional, mutable, injected, keyed service.