provide!() { /* proc-macro */ }
Expand description
Register an statically resolved service expression indexed by key.
ยงExample
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))