You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Dependency:
pass
class ConsumerOfA:
def __init__(self, dep: Dependency):
self.dep = dep
container.register('depA', Dependency('a'))
container.register('depB', Dependency('b'))
container.register(ConsumerOfA)
cOA = container.resolve(ConsumerOfA)
How do I ensure that ConsumerOfA gets depA vs depB? Is there a way to add an annotation on init to make sure the right one is injected?
The text was updated successfully, but these errors were encountered:
This could be achieved with string annotations on __init__ args:
class Dependency:
pass
class ConsumerOfA:
def __init__(self, dep: 'depA'):
self.dep = dep
container.register('depA', Dependency('a'))
container.register('depB', Dependency('b'))
container.register(ConsumerOfA)
cOA = container.resolve(ConsumerOfA)
Drawback of this approach is that you introducing DI to your client code, and this breaks static analysis tools like mypy.
lets say I have something like this:
How do I ensure that ConsumerOfA gets depA vs depB? Is there a way to add an annotation on init to make sure the right one is injected?
The text was updated successfully, but these errors were encountered: