mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-29 04:53:59 +03:00
Rename Provider.inject() -> Provider.provide_injection()
This commit is contained in:
parent
209bc518c3
commit
ab7c8ac4d1
|
@ -77,11 +77,12 @@ def inject(*args, **kwargs):
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
"""Decorated with dependency injection callback."""
|
"""Decorated with dependency injection callback."""
|
||||||
if decorated.args:
|
if decorated.args:
|
||||||
args = tuple(arg.inject() for arg in decorated.args) + args
|
args = tuple(arg.provide_injection()
|
||||||
|
for arg in decorated.args) + args
|
||||||
|
|
||||||
for name, arg in six.iteritems(decorated.kwargs):
|
for name, arg in six.iteritems(decorated.kwargs):
|
||||||
if name not in kwargs:
|
if name not in kwargs:
|
||||||
kwargs[name] = arg.inject()
|
kwargs[name] = arg.provide_injection()
|
||||||
|
|
||||||
return callback(*args, **kwargs)
|
return callback(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Provider(object):
|
||||||
"""Call last overriding provider and return result."""
|
"""Call last overriding provider and return result."""
|
||||||
return self.last_overriding(*args, **kwargs)
|
return self.last_overriding(*args, **kwargs)
|
||||||
|
|
||||||
def inject(self):
|
def provide_injection(self):
|
||||||
"""Injection strategy implementation.
|
"""Injection strategy implementation.
|
||||||
|
|
||||||
:rtype: object
|
:rtype: object
|
||||||
|
|
|
@ -97,11 +97,11 @@ class Callable(Provider):
|
||||||
:rtype: object
|
:rtype: object
|
||||||
"""
|
"""
|
||||||
if self.args:
|
if self.args:
|
||||||
args = tuple(arg.inject() for arg in self.args) + args
|
args = tuple(arg.provide_injection() for arg in self.args) + args
|
||||||
|
|
||||||
for name, arg in six.iteritems(self.kwargs):
|
for name, arg in six.iteritems(self.kwargs):
|
||||||
if name not in kwargs:
|
if name not in kwargs:
|
||||||
kwargs[name] = arg.inject()
|
kwargs[name] = arg.provide_injection()
|
||||||
|
|
||||||
return self.provides(*args, **kwargs)
|
return self.provides(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ class DelegatedCallable(Callable):
|
||||||
"as is".
|
"as is".
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def inject(self):
|
def provide_injection(self):
|
||||||
"""Injection strategy implementation.
|
"""Injection strategy implementation.
|
||||||
|
|
||||||
:rtype: object
|
:rtype: object
|
||||||
|
|
|
@ -113,7 +113,7 @@ class Factory(Callable):
|
||||||
instance = super(Factory, self)._provide(*args, **kwargs)
|
instance = super(Factory, self)._provide(*args, **kwargs)
|
||||||
|
|
||||||
for name, arg in six.iteritems(self.attributes):
|
for name, arg in six.iteritems(self.attributes):
|
||||||
setattr(instance, name, arg.inject())
|
setattr(instance, name, arg.provide_injection())
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ class DelegatedFactory(Factory):
|
||||||
:type: type
|
:type: type
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def inject(self):
|
def provide_injection(self):
|
||||||
"""Injection strategy implementation.
|
"""Injection strategy implementation.
|
||||||
|
|
||||||
:rtype: object
|
:rtype: object
|
||||||
|
@ -243,7 +243,7 @@ class DelegatedSingleton(Singleton):
|
||||||
:type: type
|
:type: type
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def inject(self):
|
def provide_injection(self):
|
||||||
"""Injection strategy implementation.
|
"""Injection strategy implementation.
|
||||||
|
|
||||||
:rtype: object
|
:rtype: object
|
||||||
|
|
|
@ -111,4 +111,4 @@ class DelegatedCallableTests(unittest.TestCase):
|
||||||
def test_is_delegated_provider(self):
|
def test_is_delegated_provider(self):
|
||||||
"""Test is_delegated_provider."""
|
"""Test is_delegated_provider."""
|
||||||
provider = providers.DelegatedCallable(len)
|
provider = providers.DelegatedCallable(len)
|
||||||
self.assertIs(provider.inject(), provider)
|
self.assertIs(provider.provide_injection(), provider)
|
||||||
|
|
|
@ -242,7 +242,7 @@ class DelegatedFactoryTests(unittest.TestCase):
|
||||||
def test_is_delegated_provider(self):
|
def test_is_delegated_provider(self):
|
||||||
"""Test is_delegated_provider."""
|
"""Test is_delegated_provider."""
|
||||||
provider = providers.DelegatedFactory(object)
|
provider = providers.DelegatedFactory(object)
|
||||||
self.assertIs(provider.inject(), provider)
|
self.assertIs(provider.provide_injection(), provider)
|
||||||
|
|
||||||
|
|
||||||
class SingletonTests(unittest.TestCase):
|
class SingletonTests(unittest.TestCase):
|
||||||
|
@ -481,7 +481,7 @@ class DelegatedSingletonTests(unittest.TestCase):
|
||||||
def test_is_delegated_provider(self):
|
def test_is_delegated_provider(self):
|
||||||
"""Test is_delegated_provider."""
|
"""Test is_delegated_provider."""
|
||||||
provider = providers.DelegatedSingleton(object)
|
provider = providers.DelegatedSingleton(object)
|
||||||
self.assertIs(provider.inject(), provider)
|
self.assertIs(provider.provide_injection(), provider)
|
||||||
|
|
||||||
|
|
||||||
class FactoryAsDecoratorTests(unittest.TestCase):
|
class FactoryAsDecoratorTests(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user