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

WiringConfiguration(packages=[top_level_package]) affect subpackages only if they have __init__.py #834

Open
hagd0520 opened this issue Dec 5, 2024 · 0 comments

Comments

@hagd0520
Copy link

hagd0520 commented Dec 5, 2024

Hello folks! I'm just started to learn dependency-injector.
I was following this public template https://github.com/teamhide/fastapi-boilerplate and found that WiringConfiguration can be affect subpackages of designated top level package only if all of paths have init.py.

I understand that from Python 3.6 we don't necessarily need to use init.py not if in some of situation but i believe this might not be one of the those cases.

app.container.py

from dependency_injector.containers import DeclarativeContainer, WiringConfiguration
from dependency_injector.providers import Factory, Singleton

from app.auth.application.service.jwt import JwtService
from app.user.adapter.output.persistence.repository_adapter import UserRepositoryAdapter
from app.user.adapter.output.persistence.sqlalchemy.user import UserSQLAlchemyRepo
from app.user.application.service.user import UserService


class Container(DeclarativeContainer):
    wiring_config = WiringConfiguration(packages=["app"])

    user_repo = Singleton(UserSQLAlchemyRepo)
    user_repo_adapter = Factory(UserRepositoryAdapter, user_repo=user_repo)
    user_service = Factory(UserService, repository=user_repo_adapter)

    jwt_service = Factory(JwtService)
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