Expand description
portaldi is an ergonomic, lightweight and compile-time dependency injection library.
Features
-
Natively async support
- components and traits must be
thread-safe(Sync + Send). - support for asynchronous component creation.
- components and traits must be
-
Ergonomic apis
- in most cases, you can use target types directly instead of using containers.
ⓘ// for a concrete type. let hoge: DI<HogeService> = HogeService::di(); // for a trait. (through DIProvider) let hoge: DI<dyn HogeService> = HogeServiceProvider::di(); -
DRY support by macros
- almost boiler codes can be generated by proc macros.
ⓘ#[derive(DIPortal)] struct HogeService { foo: DI<FooService>, ..., }
Modules
Macros
- Generate a [
AsyncDIProvider] implementation. - Generate a [
DIProvider] implementation.
Structs
- DI container holds component refs.
Traits
- Add
dimethods for DI target types that needs async creation. - Provides component instance for trait DI types that needs async creation.
- Add
dimethods for DI target types. - Provides component instance for trait DI types.
- Represent DI target type. It requires thread safety.
Type Aliases
- Represents depencency (component) type.
Attribute Macros
- Generate a [
DIProvider] or [AsyncDIProvider] implementation. (attribute macro)
Derive Macros
- Generate a
DIPortalor [AsyncDIPortal] implementation. (derive macro)