Types

Lifetime

class diwire.Lifetime(*values)[source]

Defines the lifetime of a service in the container.

SCOPED = 'scoped'

Instance is shared within a scope, different instances across scopes.

SINGLETON = 'singleton'

A single instance is created and shared for the lifetime of the container.

TRANSIENT = 'transient'

A new instance is created every time the service is requested.

Injected

class diwire.Injected[source]

Marker to indicate a parameter should be injected from the DI container.

Usage:
def my_function(service: Annotated[ServiceA, Injected()], value: int) -> None:

For type checkers, Annotated[T, Injected()] is equivalent to T. At runtime, parameters marked with Injected will be automatically injected.

Component

class diwire.Component(value: Any)[source]

Named component marker for distinguishing multiple registrations of the same type.