doc: document customization of autowiring
adriangb opened this issue · 1 comments
adriangb commented
Autowiring can easily customized (e.g. to continue auto wiring when a default value is encountered) by overriding Dependant.gather_dependencies
.
It would be good to show an examples of that.
Some ideas:
- A
depth
attribute to limit autowiring depth - Continuing auto wiring for default values
A nice real world example might be the dependency hierarchy App -> httpx.Client -> httpx.BaseTransport
. App accepts a client.
It would be nice to be able to directly inject the transport into the client in a test:
with container.bind(Dependant(lambda: MockTransport(handler=...)), BaseTransport):
app = container.execute_sync(container.solve(App))
assert isinstance(app.client._base_transport, MockTransport)
adriangb commented
This is now captured by DependantProtocol and documentation around JoinedDependant.