mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
Removing delegate option from injections
This commit is contained in:
parent
e38cecfae0
commit
acc9259ddd
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
4
tox.ini
4
tox.ini
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user