Skip to content

How to handle circular dependency [non-string keys for Dict provider] #327

@ijalalfrz

Description

@ijalalfrz

so i have handler class to be injected by container to get repositry object

service/handler.py

from ... import Container
from dependency_injector.wiring import inject, Provide
from .rating_repository import RatingRepository
from ..domain.commands import SaveRating
from ..domain.models import RunnerRating


class CommandHandler:
    # Dep Injector
    @inject
    def __init__(self, rating_repo: RatingRepository =
                 Provide[Container.repo.rating]):
        self.rating_repo = rating_repo

this handler is included in messagebus module like this

service/messagebus.py

from .handler import CommandHandler

Message = Union[Command, Event]

logger = logging.getLogger(__name__)
command_handler = CommandHandler()


COMMAND_HANDLERS = {
    SaveRating: command_handler.save_rating,
}

class MessageBus:

    def __init__(self):
        pass

    # rest methods...

but i also add MessageBus class on container that make me include service/messagebus.py to container.py

container.py

from .runner_rating.service import messagebus

'''
    Dependency injector for application
'''


class MessageBusContainer(containers.DeclarativeContainer):

    bus = providers.Container(
        messagebus.MessageBus
    )

when i run the app, it shows ImportError on container.py because i imported messagebus and inside it there is a handler object that import container.py

what should i do to solve this? because message bus will be injected to other module in future

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions