2017-10-04 00:01:49 +03:00
|
|
|
"""`FactoryAggregate` providers example."""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2017-10-04 01:28:31 +03:00
|
|
|
import dependency_injector.providers as providers
|
2017-10-04 00:01:49 +03:00
|
|
|
|
|
|
|
from games import Chess, Checkers, Ludo
|
|
|
|
|
|
|
|
|
2017-10-04 01:28:31 +03:00
|
|
|
game_factory = providers.FactoryAggregate(chess=providers.Factory(Chess),
|
|
|
|
checkers=providers.Factory(Checkers),
|
|
|
|
ludo=providers.Factory(Ludo))
|
2017-10-04 00:01:49 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
game_type = sys.argv[1].lower()
|
2017-10-04 01:28:31 +03:00
|
|
|
|
2017-10-04 00:01:49 +03:00
|
|
|
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
|