Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package level decoupling with FastAPI #797

Open
ilterisYucel opened this issue May 1, 2024 · 0 comments
Open

Package level decoupling with FastAPI #797

ilterisYucel opened this issue May 1, 2024 · 0 comments

Comments

@ilterisYucel
Copy link

ilterisYucel commented May 1, 2024

version: 4.41.0
fastapi version: 0.110.2

In the project I developed with Fastapi, I want to use di as decoupled example at the package level.
I have OwnerContainer in owner package and i have ApplicationContainer in top level main package.

`

class OwnerContainer(containers.DeclarativeContainer):

db_session = providers.Dependency()

owner_service = providers.Factory(
    OwnerService,
    db_session=db_session,
)

class ApplicationContainer(containers.DeclarativeContainer):
config = providers.Configuration()
database_session = providers.Resource(
get_db_session
)

owner_package = providers.Container(
    OwnerContainer,
    db_session=database_session
)`

I want to use OwnerService in my owner router

@owner_router.get("/", response_model=List[GetOwnerSchema]) @inject async def get_owners(service: OwnerService = Depends(Provide[OwnerContainer.owner_service])): try: result: List[GetOwnerSchema] = await service.get_owners() return result except Exception as e: print(e) raise HTTPException(status_code=500)

I got error 'Provide' object has no attribute 'get_owners'

According to my research, this is related to the dependency injector not being able to wire. I can't figure out whether this is related to a bug or whether I made a mistake, but I think I used it in accordance with the examples.
Has anyone encountered this type of problem? I need some help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant