dill

Runtime dependency injection library for Rust

[![Crates.io](https://img.shields.io/crates/v/dill.svg?style=for-the-badge)](https://crates.io/crates/dill) [![CI](https://img.shields.io/github/actions/workflow/status/sergiimk/dill-rs/build.yaml?logo=githubactions&label=CI&logoColor=white&style=for-the-badge&branch=master)](https://github.com/sergiimk/dill-rs/actions) [![Dependencies](https://deps.rs/repo/github/sergiimk/dill-rs/status.svg?&style=for-the-badge)](https://deps.rs/repo/github/sergiimk/dill-rs)

This crate is still in early stages and needs a lot of work, BUT it's in active use in kamu-cli - a fairly large project organized according to Onion/Clean Architecture. We are continuing to improve this crate as we go and encounter more sophisticated DI scenarios.

Example

```rust /////////////////////////////////////////

// Define interfaces in traits trait A: Send + Sync { fn test(&self) -> String; }

// Implement traits to define components

[component]

struct AImpl { // Auto-inject dependencies (also supports by-value) b: Arc, }

impl A for AImpl { fn test(&self) -> String { format!("aimpl::{}", self.b.test()) } }

/////////////////////////////////////////

trait B: Send + Sync { fn test(&self) -> String; }

[component]

struct BImpl;

impl B for BImpl { fn test(&self) -> String { "bimpl".to_owned() } }

/////////////////////////////////////////

// Register interfaces and bind them to implementations let cat = CatalogBuilder::new() .add::() .bind::() .add::() .bind::() .build();

// Get objects and have their deps satisfied automatically let inst = cat.get::>().unwrap(); assert_eq!(inst.test(), "aimpl::bimpl"); ```

Features

Design Principles

TODO