hynek / svcs

A Flexible Service Locator for Python.
https://svcs.hynek.me
MIT License
294 stars 19 forks source link

get_many()? #14

Closed hynek closed 1 year ago

hynek commented 1 year ago

As @glyph mentioned to me, having many services can get unnecessarily verbose and even slow.

We should consider:

db, web_api, working_q = svcs.get_many(Database, WebAPI, WorkingQueue)

It's still a for loop, but saves boilerplate and reduces business code from 3 lines to 1.

Better names appreciated.

glyph commented 1 year ago

… just give .get an @overload? It's a little ugly type-wise, but you can easily make

db = svcs.get(Database)
# or 
db, web_api = svcs.get(Database, WebAPI)

(I would not blame you for finding the single-element special-case kind of gross, but I think as a user this is what I'd want)

hynek commented 1 year ago

Hmmm, so there's been thought of allowing to pass arguments to factories, but we totally could just say kwargs only and posargs are always the getter. 🤔

What do you mean by "ugly type-wise"? Will I have to send @tinche to the typing salt mines or is does it just look ugly?