From f67343c45c638b9ba68720ae0c4f34b31d028ae7 Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Sat, 16 May 2015 22:01:03 +0300 Subject: [PATCH] Refactoring of @inject decorator --- objects/decorators.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/objects/decorators.py b/objects/decorators.py index 0113ae05..1846b3ae 100644 --- a/objects/decorators.py +++ b/objects/decorators.py @@ -15,7 +15,7 @@ def override(catalog): def inject(injection): - """Inject decorator. + """Dependency injection decorator. :type injection: Injection :return: (callable) -> (callable) @@ -23,12 +23,19 @@ def inject(injection): injection = ensure_is_injection(injection) def decorator(callback): - """Decorator.""" + """Dependency injection decorator.""" + if hasattr(callback, '__injections__'): + callback.__injections__ += (injection,) + @wraps(callback) def decorated(*args, **kwargs): - """Decorated.""" - if injection.name not in kwargs: - kwargs[injection.name] = injection.value + """Decorated with dependency injection callback.""" + for injection in getattr(decorated, '__injections__'): + if injection.name not in kwargs: + kwargs[injection.name] = injection.value return callback(*args, **kwargs) + + setattr(decorated, '__injections__', (injection,)) + return decorated return decorator