-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String provider resolution #150
String provider resolution #150
Conversation
@lesnik512 Please take a look at the general feature and let me know what you think about supporting this, the implementation needs to still be slightly reworked to actually do the provider resolution at runtime and not at import time! In other words, currently I implemented it such that I will rewrite it such that the |
@alexanderlazarev0 I feel bad about it. Don't like to encourage hacks against circular imports instead of refactoring. @vrslev What do you think? |
Yes I agree it's a bit hacky, it's just on a large code base a refactor might need time, and this serves as an easy temp fix. There has been multiple discussion on refactoring and I have experienced this myself with
This is not necessarily bad, but just FYI. The other point is decoupling, we currently have strong coupling between container and dependencies, and for testing the only feasible approach is to override provider's resolve methods, it is not possible to override a provider itself (for example it is not possible to replace a Singleton provider with a resource provider). Also, override behavior is currently not very representative of the provider since you do not override the creator but instead just the return value (but that can be addressed in a different issue). |
I didn’t dive too dip into code, but I suspect this brings some kind of global state to keep track of aliases. That’s the main thing I dislike |
No, I just use the already existing global state, the same way I resolve which resources are in Talking about global state there are currently 4 global states:
Difficulty to remove (of course the corresponding feature will also no longer be supported):
ObservationsWe can skip the whole discussion of "globals are bad practice" since they are a key feature that enables ease of use and the only way to enable dependency injection anywhere. Now, I try to keep the global's as clean as possible in my implementations, since obviously they can be a potential cause of issues. So to me, if I am going to use global's at all I am gonna at least abuse them to their full potential (while minimizing the downsides). But let me know your opinion @vrslev and @lesnik512 since I will adjust my work in accordance. |
Proposed feature:
Allow dependency injection by specifying the container and provider using a string (does not require import).
Why?
To be clear, I don't want to encourage this pattern as standard practice with
that-depends
but more an option that can help in certain scenarios such as #40.