Python Forum
super lightweight (only 35 lines) dependency injection (ioc) support for Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
super lightweight (only 35 lines) dependency injection (ioc) support for Python
#6
In a new version, I'm able to inject partial data
    class Spam:
        def __init__(self):
            self.eggs = Inject()
            self.ham = Inject()

        def __str__(self):
            return f"<Spam {self.eggs} {self.ham}>"

    spam = Wirer(spam=Spam(), ham='HAM').spam
    print(spam)
    spam = Wirer(spam=spam, eggs='EGGS').spam
    print(spam)
Output:
<Spam Inject(name=None) HAM> <Spam EGGS HAM>
In fact the Wirer behaves much like the builtin partial function. Instead of partial functions, it manipulates partial objects, or partially wired objects. This is a great paradigm!
Reply


Messages In This Thread
RE: super lightweight (only 35 lines) dependency injection (ioc) support for Python - by Gribouillis - Jan-14-2023, 03:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  D-Pad/No dependency platformer + tilemap michael1789 0 1,411 Jun-27-2020, 08:59 PM
Last Post: michael1789

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020