python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

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

Open hagd0520 opened this issue 11 months ago • 0 comments
trafficstars

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)

hagd0520 avatar Dec 05 '24 01:12 hagd0520