-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
4,158 additions
and
3,918 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""`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) |
Oops, something went wrong.