Replies: 2 comments 1 reply
-
Since @Tinche bemoaned your first point too and the rounded number of svcs users is currently "one Hynek", I think I'll change the default here. As for your second point: originally svcs was agnostic about these things, the problem is that internally it needs to be cognizant of async/or not for cleanups and pings. This might be frustrating if you don't use those features, but I'm afraid being less strict about this would lead to hard-to-debug problems. :-/ |
Beta Was this translation helpful? Give feedback.
-
Now that the default has changed I'm gonna close this now – thanks for your thoughts! |
Beta Was this translation helpful? Give feedback.
-
First of all, thanks for this library! I really like simplicity of the API. I found it to be very intuitive. I was trying to incorporate it into one of my projects and it was super easy to start using it. I am also hoping to create a plugin for Litestar to integrate
svcs
(great name, btw!).I faced some friction for setting up asynchronous singletons like a connection pool, and I think it would be nice to make the following change based on my experience:
Enter
asFalse
by default when usingregister_value
since those are supposed to act as singletons, we only want the cleanup to be happen when the registry closes and not when the container is closed. A connection pool would be a prime example.Another point was regarding the raising of the
TypeError
when using awaitable singletons if we use theContainer.get
API to get the singleton instance. When I'm setting connection pools or other await singletons, and I've already awaited it to ensure its initialization etc. then having to callaget
where it calls the__await__
method again and again seems a bit wasteful to me. I feel like it's fine to not check for whether the service is awaitable withinContainer.get
, or maybe just raise a warning instead of an error. Personally, I would prefer it to not check for whether something is awaitable or not. I think it's the user's responsibility to make sure they're calling the right API (i.e.get
oraget
).Just to give some context on the above, I was not able to use
aget
norget
when using the connection pool provided byasyncpg
. This is not an issue withsvcs
butasyncpg
since it was not returning the pool from its__await__
method if the pool was already initialized as you can see here.Beta Was this translation helpful? Give feedback.
All reactions