portaldi is a ergonomic, lightweight and compile-time dependency injection (DI) library for Rust.
Ergonomic apis for DI.
You can forcus on a target type in most cases without worrying about containers.
rust
Hoge::di().hello();
Natively async support.
In portaldi, components and trait must be thread-safe
(Sync + Send
)
Asynchronous component creation is enabled.
rust
AsyncHoge::di()
.await
.hello()
DRY support by proc-macros.
Almost boiler codes can be generated by portaldi's proc-macro.
```rust
struct Hoge {
foo: DI
```rust use portaldi::*;
struct Hoge {
foo: DI
pub trait FooI: DITarget { fn hello(&self) -> &str; }
struct Foo {}
impl FooI for Foo { fn hello(&self) -> &str { "hello foo" } }
struct Bar {}
impl Bar { fn hello(&self) -> &str { "hello bar" } }
fn main() { Hoge::di().say_hello(); }
```
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.