Giter Site home page Giter Site logo

Comments (4)

roo-oliv avatar roo-oliv commented on May 22, 2024

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.

mt3o avatar mt3o commented on May 22, 2024

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.

roo-oliv avatar roo-oliv commented on May 22, 2024

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.

roo-oliv avatar roo-oliv commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.