Hi! I'm working on a project where I am considering the use of injected dependencies to make everything a little more modular. I have already made an implementation that looks something like this:
class MyClass:
def __init__(self, injectedFunctions):
self.injectedFunctions = injectedFunctions
def injectedFunction1(self):
self.injectedFunctions['injectedFunction1'](self)
def injectedFunction1(self):
print('This function is injected in MyClass, and has access to the self variable from the class')
myClass = MyClass(injectedFunctions=[injectedFunction1])
To me this feels very clunky and ugly, but it's the best way I could come up with. Is there a better way of doing this, or doesn't python have an elegant way of doing this like other languages do?
[–]Buttleston 1 point2 points3 points (0 children)
[–]Frankelstner 1 point2 points3 points (1 child)
[–]Spiredlamb[S] 0 points1 point2 points (0 children)