python-dependency-injector/examples/miniapps/commands-and-handlers/application/containers.py

24 lines
667 B
Python
Raw Permalink Normal View History

2020-11-21 02:09:34 +03:00
"""Containers module."""
from dependency_injector import containers, providers
from . import repositories, handler, messagebus, commands
class Container(containers.DeclarativeContainer):
rating_repository = providers.Singleton(repositories.RatingRepository)
command_handler = providers.Singleton(
handler.CommandHandler,
rating_repo=rating_repository,
)
message_bus = providers.Factory(
messagebus.MessageBus,
command_handlers=providers.Dict({
commands.SaveRating: command_handler.provided.save_rating,
commands.DoSomethingElse: command_handler.provided.something_else,
}),
)