Crate portaldi

Source
Expand description

PortalDI is an ergonomic, lightweight and compile-time dependency injection library.

§Features

  • Natively async support

    • Support for asynchronous component creation.
    • Components and traits must be thread-safe (Sync + Send) in non Wasm target.
  • 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§

docs

Macros§

async_di_provider
Generate a [AsyncDIProvider] implementation.
di_provider
Generate a [DIProvider] implementation.

Structs§

DIContainer
DI container holds component refs.

Traits§

AsyncDIPortal
Add di methods for DI target types that needs async creation.
AsyncDIProvider
Provides component instance for trait DI types that needs async creation.
DIPortal
Add di methods for DI target types.
DIProvider
Provides component instance for trait DI types.
DITarget

Type Aliases§

DI
Represents depencency (component) type.

Attribute Macros§

provider
Generate a [DIProvider] or [AsyncDIProvider] implementation. (attribute macro)

Derive Macros§

DIPortal
Generate a DIPortal and [DIProvider] or [AsyncDIPortal] and [AsyncDIProvider] implementation.