runtimeinjectoractix

Current version Current documentation

This library provides types to help with injecting services into actix-web applications.

Getting started

Create your injector, then add it as app data to your application:

```rust

[actix::main]

async fn main() -> std::io::Result<()> { // Define a module so the let module = definemodule! { #[cfg(not(test))] services = [ UserAuthenticator::new.transient(), ], #[cfg(not(debugassertions))] interfaces = { dyn UserDatabase = [SqlUserDatabase::new.singleton()], }, #[cfg(debug_assertions)] interfaces = { dyn UserDatabase = [JsonUserDatabase::new.singleton()], }, };

let mut builder = Injector::builder();
builder.add_module(module);

let injector = builder.build();

HttpServer::new(|| App::new().app_data(injector.clone()).service(index))
    .bind(("127.0.0.1", 8080))?
    .run()
    .await

} ```

Inject dependencies with Injected<R> in your request handlers:

```rust

[get("/")]

async fn index( userdb: Injected>, userauth: Injected>, ) -> impl Responder { todo!() } ```

Minimum supported Rust version

As the library is still in development, the only supported Rust version is the most recent version of stable Rust. The library may work on older versions, but there is no guarantee.

License

This library is licensed under your choice of either MIT or Apache 2.0.