punq icon indicating copy to clipboard operation
punq copied to clipboard

Priority for kwargs, or support for recursive resolve

Open prefect4742 opened this issue 2 years ago • 1 comments

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?

prefect4742 avatar Feb 02 '23 07:02 prefect4742

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.

bobthemighty avatar Mar 27 '23 10:03 bobthemighty