diff --git a/docs/providers/index.rst b/docs/providers/index.rst index b1d561eb..621959e3 100644 --- a/docs/providers/index.rst +++ b/docs/providers/index.rst @@ -29,7 +29,7 @@ be thread safe. factory singleton callable + object external_dependency - static overriding custom diff --git a/docs/providers/object.rst b/docs/providers/object.rst new file mode 100644 index 00000000..5a20391d --- /dev/null +++ b/docs/providers/object.rst @@ -0,0 +1,12 @@ +Object providers +---------------- + +.. currentmodule:: dependency_injector.providers + +:py:class:`Object` provider returns provided instance "as is" + +Example: + +.. literalinclude:: ../../examples/providers/object.py + :language: python + :linenos: diff --git a/docs/providers/static.rst b/docs/providers/static.rst deleted file mode 100644 index 508afdff..00000000 --- a/docs/providers/static.rst +++ /dev/null @@ -1,22 +0,0 @@ -Static providers ----------------- - -.. currentmodule:: dependency_injector.providers - -Static providers are family of providers that return their values "as is". -There are four types of static providers: - - - :py:class:`Class` - - :py:class:`Object` - - :py:class:`Function` - - :py:class:`Value` - -All of them have the same behaviour (inherited from -:py:class:`StaticProvider`), but usage of any is predicted by readability -and providing object's type. - -Example: - -.. literalinclude:: ../../examples/providers/static.py - :language: python - :linenos: diff --git a/examples/providers/object.py b/examples/providers/object.py new file mode 100644 index 00000000..f3fa6693 --- /dev/null +++ b/examples/providers/object.py @@ -0,0 +1,10 @@ +"""Object providers example.""" + +import dependency_injector.providers as providers + + +# Creating object provider: +object_provider = providers.Object(1) + +# Making some asserts: +assert object_provider() == 1 diff --git a/examples/providers/static.py b/examples/providers/static.py deleted file mode 100644 index fbfd32d2..00000000 --- a/examples/providers/static.py +++ /dev/null @@ -1,20 +0,0 @@ -"""Static providers example.""" - -import dependency_injector.providers as providers - - -# Provides class - `object`: -cls_provider = providers.Class(object) -assert cls_provider() is object - -# Provides object - `object()`: -object_provider = providers.Object(object()) -assert isinstance(object_provider(), object) - -# Provides function - `len`: -function_provider = providers.Function(len) -assert function_provider() is len - -# Provides value - `123`: -value_provider = providers.Value(123) -assert value_provider() == 123