mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-27 03:54:00 +03:00
28 lines
680 B
Python
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
|