punq
punq copied to clipboard
Priority for kwargs, or support for recursive resolve
Two separate issues but they are related. I have classes that are nodes in a tree and I would like to be able to send in a registered entity as a parameter in kwargs when calling resolve(), like this:
class Example:
def __init__(self, parent: 'Example', someParam: str):
...
parentExample = container.resolve(parent=None, someParam="Hello")
oneExample = container.resolve(parent=parentExample, someParam="world")
But as I understand the code in resolve_impl, punq will try to resolve any "needs" (registered) parameters first which would cause a loop in the __init__ code above, correct?
Is there some way to achieve this other than registering factory classes?
Hey @prefect4742
Sorry for the delayed reply. That sounds like a sensible change. I might take a look this week and see what's involved in implementing it this way.