Skip to content

Descriptors API

wd.di.descriptors.ServiceDescriptor dataclass

Bases: Generic[T]

Immutable description of a service registration.

Attributes

service_type: The abstraction that clients request—usually an interface or base class. implementation_type: The concrete class that will be instantiated to satisfy the registration. Mutually exclusive with factory. factory: A callable that builds the instance given the current service provider. Mutually exclusive with implementation_type. lifetime: Controls how long the resulting object lives (transient, scoped, singleton). decorators: An ordered list of :data:DecoratorFactory objects to be applied to the instance after construction but before lifetime caching.

with_decorator(decorator)

Return a new descriptor with decorator appended to the chain.

The method does not modify the original object (dataclass is frozen) but returns a new instance that shares all existing attributes.

wd.di.descriptors.DecoratorFactory = Callable[['ServiceProvider', Any], Any] module-attribute

Callable that takes the current :class:~wd.di.container.ServiceProvider and the inner instance and returns a (possibly) wrapped instance. The return type is Any on purpose to allow the decorator to change the runtime subtype while still respecting the semantic contract of T at the call site.