python-dependency-injector/examples/providers/factory_aggregate/example.py
2017-10-13 10:27:06 -07:00

28 lines
680 B
Python

"""`FactoryAggregate` providers example."""
import sys
import dependency_injector.providers as providers
from games import Chess, Checkers, Ludo
game_factory = providers.FactoryAggregate(chess=providers.Factory(Chess),
checkers=providers.Factory(Checkers),
ludo=providers.Factory(Ludo))
if __name__ == '__main__':
game_type = sys.argv[1].lower()
selected_game = game_factory.create(game_type)
selected_game.play()
# $ python example.py chess
# Playing chess
# $ python example.py checkers
# Playing checkers
# $ python example.py ludo
# Playing ludo