Skip to content

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

@hagd0520

Description

@hagd0520

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions