diff --git a/dependency_injector/providers.py b/dependency_injector/providers.py index b9f49696..59e1c314 100644 --- a/dependency_injector/providers.py +++ b/dependency_injector/providers.py @@ -264,6 +264,11 @@ class Callable(Provider): return self.callback(*_get_injectable_args(args, self.args), **_get_injectable_kwargs(kwargs, self.kwargs)) + @property + def injections(self): + """Return tuple of all injections.""" + return self.args + self.kwargs + class Config(Provider): """Config provider. diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index f1b62b10..3a3af526 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -17,9 +17,13 @@ Development version examples. - Add functionality for using positional argument injections with ``di.Factory``, ``di.Singleton`` and ``di.Callable`` providers. +- Add functionality for decorating classes with ``@di.inject``. +- Add ``di.Singleton.injections`` attribute that represents a tuple of all + ``di.Singleton`` injections (including args, kwargs, attributes and methods). +- Add ``di.Callable.injections`` attribute that represents a tuple of all + ``di.Callable`` injections (including args and kwargs). - Add optimization for ``di.Injection.value`` property that will compute type of injection once, instead of doing this on every call. -- Add functionality for decorating classes with ``@di.inject``. - Add support of Python 3.5. - Add support of six 1.10.0. - Add minor refactorings and code style fixes. diff --git a/tests/test_providers.py b/tests/test_providers.py index 7161acb9..ce1ba801 100644 --- a/tests/test_providers.py +++ b/tests/test_providers.py @@ -755,6 +755,11 @@ class CallableTests(unittest.TestCase): self.assertTupleEqual(provider(), (1, 2, 3, 4)) + def test_injections(self): + """Test getting a full list of injections using injections property.""" + provider = di.Factory(self.example, 1, 2, arg3=3, arg4=4) + self.assertEquals(len(provider.injections), 4) + class ConfigTests(unittest.TestCase): """Config test cases."""