rdi 0.1.0

Simple dependency injection library for rust.
Documentation
  • Coverage
  • 44.44%
    4 out of 9 items documented1 out of 7 items with examples
  • Size
  • Source code size: 6.49 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.42 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dudykr/rust-commons
    2 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kdy1

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.

Usage

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

    my_handler()
}

pub trait Db {
    fn call(&self);
}

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

struct OkDb {}

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

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