Removing delegate option from injections

This commit is contained in:
Roman Mogilatov 2015-07-11 23:34:23 +03:00
parent e38cecfae0
commit acc9259ddd
3 changed files with 7 additions and 9 deletions

View File

@ -52,10 +52,9 @@ class UserService(object):
# Users factory and UserService provider:
users_factory = Factory(User)
users_service = Singleton(UserService,
KwArg('users_factory',
Delegate(Factory(User))))
KwArg('users_factory', Delegate(users_factory)))
# Creating several User objects:
user1 = users_service().get_by_id(1)

View File

@ -8,18 +8,17 @@ class Injection(object):
"""Base injection class."""
__IS_OBJECTS_INJECTION__ = True
__slots__ = ('name', 'injectable', 'delegate')
__slots__ = ('name', 'injectable')
def __init__(self, name, injectable, delegate=False):
def __init__(self, name, injectable):
"""Initializer."""
self.name = name
self.injectable = injectable
self.delegate = delegate
@property
def value(self):
"""Return injectable value."""
if is_provider(self.injectable) and not self.delegate:
if is_provider(self.injectable):
return self.injectable()
return self.injectable

View File

@ -39,14 +39,14 @@ basepython=python2.7
deps=
flake8
commands=
flake8 --max-complexity=8 objects
flake8 --max-complexity=8 objects/
[testenv:pep257]
basepython=python2.7
deps=
pep257
commands=
pep257 objects
pep257 objects/
[testenv:py26]
basepython=python2.6