mmerickel / wired

A service locator implementation for Python.
https://wired.readthedocs.io
MIT License
17 stars 9 forks source link

pass-props-into-injector #33

Closed pauleveritt closed 5 years ago

pauleveritt commented 5 years ago

For wired_components, allow passed in "props". If this looks ok, and the docs cleanup is merged, I'll then add docs for this.

mmerickel commented 5 years ago

the Injector is just a service factory and the factory api is (container) right now - I can't accept this on its own as it's nonsensical in the current state of the rest of the library

pauleveritt commented 5 years ago

Hmm, ok. Should I have Props as a singleton and stash it in the container?

mmerickel commented 5 years ago

I mean I don't know what you're using it for so I can't answer that. I just know whatever it is doesn't work in its current form.

mmerickel commented 5 years ago

If you wrote an integration test you'd see - it only works cuz it's testing against your dummy objects.

pauleveritt commented 5 years ago

How I'm using it: in a Jinja2 template you do {{ Breadcrumb(label='Home', href='/') }} and a Breadcrumb is looked up, with those two values passed into its construction, which might get other fields from DI.

I can't really put those values in the container, as there are lots of of these getting created per request.

mmerickel commented 5 years ago

The injector isn't a public api but it sounds like you're using it as such somehow. You'd have to paste a more complete example that actually uses wired.

pauleveritt commented 5 years ago

The code I have right now might be kind of hard to sort out the indirections. If you're ok with it, I'll push and give some explanations. Or, I can extract it into some standalone case, maybe.

Of course you might have a spasm seeing my indirections and give me a far better path. I struggled with it, not happy with where I'm at.

mmerickel commented 5 years ago

On its face this is a simple change, but it's directly competing with some other ideas I've been thinking about which would allow passing in props per-instance to the factory. This change to the injector doesn't change anything publicly in wired and thus doesn't serve a purpose to me. I think you should just vendor the injector if you're using it - in my mind the injector exists solely to work as a factory in wired and thus should support the minimal functionality that wired needs. If I change how passing props to factories works, I don't want this feature here to make that more difficult to support.