mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-04-28 04:53:46 +03:00
28 lines
630 B
Python
28 lines
630 B
Python
"""Application module."""
|
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import Depends, FastAPI
|
|
|
|
from dependency_injector.wiring import Provide, inject
|
|
|
|
from .containers import Container
|
|
from .services import Service
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.api_route("/")
|
|
@inject
|
|
async def index(
|
|
service: Annotated[Service, Depends(Provide[Container.service])]
|
|
) -> dict[str, str]:
|
|
value = await service.process()
|
|
return {"result": value}
|
|
|
|
|
|
container = Container()
|
|
container.config.redis_host.from_env("REDIS_HOST", "localhost")
|
|
container.config.redis_password.from_env("REDIS_PASSWORD", "password")
|
|
container.wire(modules=[__name__])
|