mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-12-01 22:14:04 +03:00
29 lines
524 B
Python
29 lines
524 B
Python
"""`Factory` provider attribute injections example."""
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
class Client:
|
|
...
|
|
|
|
|
|
class Service:
|
|
def __init__(self) -> None:
|
|
self.client = None
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
client = providers.Factory(Client)
|
|
|
|
service = providers.Factory(Service)
|
|
service.add_attributes(clent=client)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
container = Container()
|
|
|
|
service = container.service()
|
|
|
|
assert isinstance(service.client, Client)
|