def inject_function(f):
full_arg_spec = inspect.getfullargspec(f)
args = full_arg_spec.args
annotations = full_arg_spec.annotations
def _inner(self):
container = Container()
objects = {}
for arg in args:
if arg in ('self',):
continue
try:
obj_type = annotations[arg]
except KeyError:
obj_type = arg
obj = container.get_object(obj_type)
objects[arg] = obj
setattr(self, arg, obj)
return f(self, **objects)
return _inner
评论列表
文章目录