Comments (4)
Hi @mt3o! Thank you for the issue with a reproducible minimum example
I can confirm that this is a bug affecting injectable 3.4.4 and all prior 3.x releases. While I work on the fix the suggested workaround is to invoke load_injection_container
on a path it will find at least one injectable class to force it to create the namespace and then you can use clear_injectables
to remove any unwanted dependencies registered.
I will keep you posted on when the fix is released.
from injectable.
Hi @allrod5!
I discovered another scenario related to the bug:
load_injection_container('../..') # points to valid source of objects
reset_injection_container()
register_injectables({ Injectable(lambda: make_context())}, GlobalContext)
The same bug appears. Not calling reset_injection_container
but calling clear_injectables
helps.
Regardless, I have to say, you did an awesome piece of work with this library. The DI from ets labs is quite complicated, imho you found the balance between simplicity of code, ways to use, and functionality. My app instantiates several dozens of objects and calle them when they match a protocol - so I heavily rely on injecting lists of items that match the assumed type. I tried using libraries that provide js-like events, but they lack the stopPropagation()
, preventDefault()
and isDefaultPrevented()
methods that are present in js, and I need each object from the list to be able to break the chain of commands.
Do you think it would be possible to inject items that do not inherit the given protocol class (as instantiable classes should not subclass Protocol
) but match a protocol on runtime? Could it be a feature request? :)
from injectable.
Hi @mt3o, thanks for your feedback ❤️ and for sharing your thoughts.
Update on the bug: the fix is really easy and is on the way!
Regarding this other piece of code that reproduces the bug, there is really nothing different from the original code actually because when you can reset_injection_container
you're not just clearing injectables from a namespace but wiping clean the whole container so all namespaces are being trashed as well just like as if load_injection_container
was never called. I can see that maybe you were expecting reset_injection_container
to behave similarly to clear_injectables
but clearing all injectables at once. Once this bug is fixed I see no strong reason to create a clear_all_injectables
utility with such behavior but I'm open to discussing that if anyone comes up with a good use case 🙂
About the feature request, I'm not that familiar with the js events system so a more concrete example would help me there. I think it would be best to discuss this possible feature in a separate GitHub issue though.
from injectable.
Hi @mt3o, just passing by to inform you that the fix has been released in version 3.4.6 and already is available at PyPI. Thanks for your help on this bug! 🎉
from injectable.
Related Issues (19)
- Lazy type class HOT 4
- Enable `@autowired` decorator to be called without parenthesis HOT 1
- Original function's signature overwrite
- Autowiring should be done without actually importing the dependency's class HOT 5
- Autowired(List[...]) does not work with qualifiers
- Using named args breaks injectable
- Optional injection doesn't work when there are the namespce is empty
- Making typing.Type injectable. HOT 5
- Evaluate the use of code scanning tools other than SonarQube
- Injectable fails to resolve entangled imports
- [Feature Request] Manually supplying injectables HOT 4
- [Bug] inject method signature accepts T instead of Type[T] HOT 1
- ImportError due to changes in 3.4.3 HOT 3
- Missing encoding in container injection HOT 2
- Official Support for Python 3.9 HOT 1
- First-class support for testing HOT 2
- Support for async injectables HOT 6
- Comply with PEP-593 and support typing.Annotated HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from injectable.