rdi 0.1.0

Simple dependency injection library for rust.

Dependency injection for the rust.

This is currently in state of proof-of-concept. It currently does not support

  • providing variables to the injector
  • injection of variable into other method in injector.
  • returning references while defining injection rules.

Note: It works by cloing all components, so you have to return Arc<T> or Rc<T>. This is because the injector cannot know how much time it will be injected.


fn main() {
let injector = ok_injector();
let my_handler = injector.inject(handler);


pub trait Db {
fn call(&self);

pub fn handler(#[inject] db: Arc<dyn Db>) {

struct OkDb {}

impl Db for OkDb {
fn call(&self) {}

fn ok_injector() {
fn db() -> Arc<dyn Db> {
Arc::new(OkDb {})