mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-23 18:13:56 +03:00
28 lines
658 B
Python
28 lines
658 B
Python
"""`FactoryAggregate` providers example."""
|
|
|
|
import sys
|
|
|
|
from dependency_injector.providers import Factory
|
|
|
|
from prototype import FactoryAggregate
|
|
from games import Chess, Checkers, Ludo
|
|
|
|
|
|
game_factory = FactoryAggregate(chess=Factory(Chess),
|
|
checkers=Factory(Checkers),
|
|
ludo=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
|