sdi

Crates.iosdi
lib.rssdi
version0.1.1
sourcesrc
created_at2023-06-07 12:14:34.153923
updated_at2023-06-08 00:10:20.410803
descriptionRust statically resolved dependency injection lib
homepagehttps://github.com/Thaumy/sdi
repository
max_upload_size
id884710
size5,688
Thaumy (Thaumy)

documentation

README

sdi

Rust statically resolved dependency injection library

Usage

provide!

Register an statically resolved service expression indexed by key.

use sdi::{inject, provide};

#[derive(Debug, PartialEq)]
struct A;

impl A {
    pub fn new() -> A { A }
    provide!(A <- A::new());
}

assert_eq!(A::new(), inject!(A))

Provide by inject is also ok.

use sdi::{inject, provide};

#[derive(Debug, PartialEq)]
struct A;
provide!(A <- A);

#[derive(Debug, PartialEq)]
struct B(A);

impl B {
    pub fn new(a:A) -> B { B(a) }
    provide!(B <- B::new(inject!(A)));
}

assert_eq!(B::new(A), inject!(B))

inject!

Get an statically resolved service expression by key.

use sdi::{inject, provide};

#[derive(Debug, PartialEq)]
struct A;

impl A {
    pub fn new() -> A { A }
    provide!(A <- A::new());
}

assert_eq!(A::new(), inject!(A))
Commit count: 0

cargo fmt