#[derive(DIPortal)]
{
// Attributes available to this derive:
#[provide]
#[inject]
}
Expand description
Generate a DIPortal or [AsyncDIPortal] implementation. (derive macro)
-
provide: generate [DIProvider] implementation for a specified trait.ⓘ#[derive(DIPortal)] #[provide(HogeI)] // HogeIProvider will be generated. struct Hoge { foo: DI<dyn FooI> // needs FooIProvider in the current scope. } -
inject: specify DI settings for a field.ⓘ#[derive(DIPortal)] struct Hoge { #[inject(Foo)] // specify concrete type foo: DI<dyn FooI>, #[inject(AsyncFoo, async)] // specify concrete type that needs async creation, // and consequently AsyncDIPortal for Hoge will be generated. foo2: DI<dyn FooI>, #[inject(async)] // Bar nedds async creation, // and consequently AsyncDIPortal for Hoge will be generated. bar: DI<Bar>, #[inject(MyBazProvider)] // specify DI provider for a another crate concrete type. baz: DI<Baz>, #[inject(with_provider)] // specify DI provider for a another crate concrete type (short hand notation). baz2: DI<Baz>, }