Replies: 3 comments
-
FWIW I have a registry project with the kind of injection you describe. It’s critical for a larger effort I have in mind. I’m investigating re-homing my stuff atop svcs… going through a gap analysis now to see which of my darlings (features) to kill. |
Beta Was this translation helpful? Give feedback.
-
To my understanding we have a couple of corner cases here:
One benefit I see for factory builder over registry method is ability to customize factory: fctr = make_factory(Srvc)
def factory(svcs_container):
with fctr(svcs_container) as instance:
yield instance
registry.register(Srvc, factory) In case our service has it's own life circle an supposed to be used as context manager. |
Beta Was this translation helpful? Give feedback.
-
@hynek let me put it this way 🌴 🍸 |
Beta Was this translation helpful? Give feedback.
-
As it just came up in #86, I use a pattern similar to this all the time:
svcs will always be non-magical by default, but I guess nothing speaks against adding a helper that makes the lambda superfluous by looking at the type hints of the factory and calling
svcs_container.(a)get
on the required types automatically:Since this would only be a helper, it wouldn't also have the pressure to implement all edge cases because the escape hatch of just writing your own lambda is always there.
Beta Was this translation helpful? Give feedback.
All reactions