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 and UserService provider:
users_factory = Factory(User)
users_service = Singleton(UserService, users_service = Singleton(UserService,
KwArg('users_factory', KwArg('users_factory', Delegate(users_factory)))
Delegate(Factory(User))))
# Creating several User objects: # Creating several User objects:
user1 = users_service().get_by_id(1) user1 = users_service().get_by_id(1)

View File

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

View File

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