Skip to content

lagom backend

Wraps lagom.

Installation

pip install "django-autowired[lagom]"

Scope mapping

Scope Behavior
SINGLETON Uses lagom.Singleton wrapper
TRANSIENT New instance each resolution
THREAD Falls back to TRANSIENT (lagom has no thread scope)

@inject is not used

Lagom auto-resolves concrete classes from type hints — you don't need to decorate __init__. Only bind_to registrations need explicit definition.

@injectable()
class EmailService:
    def __init__(self, smtp: SmtpClient) -> None:
        self.smtp = smtp

Overrides

Lagom raises DuplicateDefinition on re-binding, so the adapter stores overrides in a per-backend dict and consults it before delegating to the container.

container.override({IGreeter: FakeGreeter()})

Raw access

be = container.get_backend_instance()
raw: lagom.Container = be.raw()