diff --git a/objects/__init__.py b/objects/__init__.py index b249cb20..e735b05c 100644 --- a/objects/__init__.py +++ b/objects/__init__.py @@ -1,16 +1,43 @@ """Objects.""" from .catalog import AbstractCatalog, overrides -from .providers import (Provider, NewInstance, Singleton, Class, Object, - Function, Value) -from .injections import InitArg, Attribute, Method + +from .providers import Provider +from .providers import ProviderDelegate +from .providers import NewInstance +from .providers import Singleton +from .providers import Scoped +from .providers import ExternalDependency +from .providers import Class +from .providers import Object +from .providers import Function +from .providers import Value +from .providers import Callable +from .providers import Config + +from .injections import InitArg +from .injections import Attribute +from .injections import Method -__all__ = ('AbstractCatalog', 'overrides', +__all__ = ('AbstractCatalog', + 'overrides', # Providers - 'Provider', 'NewInstance', 'Singleton', 'Class', - 'Object', 'Function', 'Value', + 'Provider', + 'ProviderDelegate', + 'NewInstance', + 'Singleton', + 'Scoped', + 'ExternalDependency', + 'Class', + 'Object', + 'Function', + 'Value', + 'Callable', + 'Config', # Injections - 'InitArg', 'Attribute', 'Method') + 'InitArg', + 'Attribute', + 'Method') diff --git a/objects/providers.py b/objects/providers.py index 56869499..85b19c4a 100644 --- a/objects/providers.py +++ b/objects/providers.py @@ -1,12 +1,11 @@ """Standard providers.""" from collections import Iterable -from .injections import ( - Injection, - InitArg, - Attribute, - Method, -) + +from .injections import Injection +from .injections import InitArg +from .injections import Attribute +from .injections import Method class Provider(object): @@ -249,29 +248,6 @@ class Callable(Provider): return self.calls(*args, **injections) -class _DeferredConfig(Provider): - - """Deferred config provider. - - Deferred config providers provide an value from the root config object. - """ - - def __init__(self, paths, root_config): - """Initializer.""" - self.paths = paths - self.root_config = root_config - super(_DeferredConfig, self).__init__() - - def __getattr__(self, item): - """Return instance of deferred config.""" - return _DeferredConfig(paths=self.paths + (item,), - root_config=self.root_config) - - def __call__(self, *args, **kwargs): - """Return provided instance.""" - return self.root_config(self.paths) - - class Config(Provider): """Config provider. @@ -302,7 +278,30 @@ class Config(Provider): if paths: for path in paths: value = value[path] - return value + return value + + +class _DeferredConfig(Provider): + + """Deferred config provider. + + Deferred config providers provide an value from the root config object. + """ + + def __init__(self, paths, root_config): + """Initializer.""" + self.paths = paths + self.root_config = root_config + super(_DeferredConfig, self).__init__() + + def __getattr__(self, item): + """Return instance of deferred config.""" + return _DeferredConfig(paths=self.paths + (item,), + root_config=self.root_config) + + def __call__(self, *args, **kwargs): + """Return provided instance.""" + return self.root_config(self.paths) def _fetch_injections(injections, injection_type):