def inject(**bindings):
def outer_wrapper(f):<EOL><INDENT>def function_wrapper(ff):<EOL><INDENT>for key, value in viewitems(bindings):<EOL><INDENT>bindings[key] = BindingKey(value)<EOL><DEDENT>@functools.wraps(ff)<EOL>def _inject(*args, **kwargs):<EOL><INDENT>inj = get_current_app().injector<EOL>dependencies = inj.args_to_inject(<EOL>function=ff,<EOL>bindings=bindings,<EOL>owner_key=ff<EOL>)<EOL>dependencies.update(kwargs)<EOL>try:<EOL><INDENT>return ff(*args, **dependencies)<EOL><DEDENT>except TypeError as e:<EOL><INDENT>reraise(e, CallError(ff, args, dependencies, e))<EOL><DEDENT><DEDENT>return _inject<EOL><DEDENT>'''<STR_LIT>'''<EOL>def method_or_class_wrapper(*a, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>inj = get_current_app().injector<EOL>inj.install_into(a[<NUM_LIT:0>])<EOL>inject_f = injector.inject(**bindings)<EOL>return inject_f(f)(*a, **kwargs)<EOL><DEDENT>if inspect.ismethod(f):<EOL><INDENT>return method_or_class_wrapper<EOL><DEDENT>else:<EOL><INDENT>return function_wrapper(f)<EOL><DEDENT><DEDENT>return outer_wrapper<EOL>
Decorator for injecting parameters for ASL objects.