Source code for ferrosoft.apps.ferrobase.containers
# Copyright (c) 2026 Ferrosoft GmbH. All rights reserved.
from dependency_injector import containers, providers
from httpx import AsyncClient
from ferrosoft.apps.ferrobase.services.taskqueue import CheapyTaskQueue
[docs]
class Container(containers.DeclarativeContainer):
"""Ferrobase dependency injection container.
Provides a shared HTTPX ``AsyncClient`` and a factory for the cheapyq task
queue. Configuration is injected from Django settings via the
``FERROBASE_CONTAINER`` key inside ``AppConfig.ready``.
"""
# Configuration is passed in AppConfig.ready, taken from Django settings.
config = providers.Configuration(
default={
"cheapyq": {
"base_url": "http://localhost:8090",
"request_timeout": 5,
}
}
)
# Default HTTPX client. Note that ASGI lifespan context manager also sets
# the httpx_client in request state, which is preferred over this one.
httpx_client = providers.Singleton(AsyncClient)
task_queue = providers.Factory(
CheapyTaskQueue,
base_url=config.cheapyq.base_url,
request_timeout=config.cheapyq.request_timeout.as_int(),
client=httpx_client,
)