mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
14d8ed909b
* Improve FactoryAggregate typing stub * Add implementation, typing stubs, and tests * Update changelog * Fix deepcopying * Add example * Update docs * Fix errors formatting for pypy3
46 lines
763 B
Python
46 lines
763 B
Python
"""`FactoryAggregate` provider with non-string keys example."""
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
class Command:
|
|
...
|
|
|
|
|
|
class CommandA(Command):
|
|
...
|
|
|
|
|
|
class CommandB(Command):
|
|
...
|
|
|
|
|
|
class Handler:
|
|
...
|
|
|
|
|
|
class HandlerA(Handler):
|
|
...
|
|
|
|
|
|
class HandlerB(Handler):
|
|
...
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
handler_factory = providers.FactoryAggregate({
|
|
CommandA: providers.Factory(HandlerA),
|
|
CommandB: providers.Factory(HandlerB),
|
|
})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
container = Container()
|
|
|
|
handler_a = container.handler_factory(CommandA)
|
|
handler_b = container.handler_factory(CommandB)
|
|
|
|
assert isinstance(handler_a, HandlerA)
|
|
assert isinstance(handler_b, HandlerB)
|