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

24 lines
667 B
Python
Raw Permalink Normal View History

2020-11-20 23:09:34 +00: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,
}),
)