From f67dab1f039b6422a4d4d437273b5da6bd1e009f Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Thu, 13 Aug 2020 21:53:13 -0400 Subject: [PATCH] Bump version to 3.30.1 --- README.rst | 177 ++++++++++++---------------- docs/main/changelog.rst | 5 + examples/di_demo2/config.yml | 2 + examples/di_demo2/demo.py | 39 ++++++ src/dependency_injector/__init__.py | 2 +- 5 files changed, 120 insertions(+), 105 deletions(-) create mode 100644 examples/di_demo2/config.yml create mode 100644 examples/di_demo2/demo.py diff --git a/README.rst b/README.rst index 596c6c28..5bbec936 100644 --- a/README.rst +++ b/README.rst @@ -52,7 +52,78 @@ What is ``Dependency Injector``? ``Dependency Injector`` is a dependency injection framework for Python. -It stands on two principles: +It provides you with the container and the providers that help you build your application objects: + +.. code-block:: python + + from dependency_injector import containers, providers + + + class ApiClient: + + def __init__(self, api_key: str, timeout: int): + self.api_key = api_key + self.timeout = timeout + + + class Service: + + def __init__(self, api_client: ApiClient): + self.api_client = api_client + + + class Container(containers.DeclarativeContainer): + + config = providers.Configuration() + + api_client = providers.Singleton( + ApiClient, + api_key=config.api_key, + timeout=config.timeout, + ) + + service = providers.Factory( + Service, + api_client=api_client, + ) + + + if __name__ == '__main__': + container = Container() + container.config.from_yaml('config.yml') + + service = container.service() + + assert isinstance(service.api_client, ApiClient) + +`More examples `_ + +Installation +------------ + +The package is available on the `PyPi`_:: + + pip install dependency-injector + +Documentation +------------- + +The documentation is available on the `Read The Docs `_ + +Tutorials +--------- + +Choose one of the following: + +- `Flask web application tutorial `_ +- `Aiohttp REST API tutorial `_ +- `Asyncio monitoring daemon tutorial `_ +- `CLI application tutorial `_ + +Concept +------- + +``Dependency Injector`` stands on two principles: - Explicit is better than implicit (PEP20). - Do no magic to your code. @@ -69,110 +140,8 @@ How does it different from the other frameworks? The power of the ``Dependency Injector`` is in its simplicity and straightforwardness. It is a simple tool for the powerful concept. -Example -======= - -With the ``Dependency Injector`` you keep **application structure in one place**. -This place is called **the container**. You use the container to manage all the components of the -application. All the component dependencies are defined explicitly. This provides the control on -the application structure. It is **easy to understand and change** it. - -.. figure:: https://raw.githubusercontent.com/wiki/ets-labs/python-dependency-injector/img/di-map.svg - :target: https://github.com/ets-labs/python-dependency-injector - -*The container is like a map of your application. You always know what depends on what.* - -Example application container: - -.. code-block:: python - - import logging - import sys - - from dependency_injector import containers, providers - - from . import http, monitors, dispatcher - - - class ApplicationContainer(containers.DeclarativeContainer): - - config = providers.Configuration() - - configure_logging = providers.Callable( - logging.basicConfig, - stream=sys.stdout, - level=config.log.level, - format=config.log.format, - ) - - http_client = providers.Factory(http.HttpClient) - - example_monitor = providers.Factory( - monitors.HttpMonitor, - http_client=http_client, - options=config.monitors.example, - ) - - httpbin_monitor = providers.Factory( - monitors.HttpMonitor, - http_client=http_client, - options=config.monitors.httpbin, - ) - - dispatcher = providers.Factory( - dispatcher.Dispatcher, - monitors=providers.List( - example_monitor, - httpbin_monitor, - ), - ) - -Example of running of such application: - -.. code-block:: python - - from .containers import ApplicationContainer - - - def main() -> None: - container = ApplicationContainer() - - container.config.from_yaml('config.yml') - container.configure_logging() - - dispatcher = container.dispatcher() - dispatcher.run() - - - if __name__ == '__main__': - main() - -Tutorials -========= - -Tutorial is a good point to start. - -Choose one of the following: - -- `Flask web application tutorial `_ -- `Aiohttp REST API tutorial `_ -- `Asyncio monitoring daemon tutorial `_ -- `CLI application tutorial `_ - -Installation -============ - -- The package is available on the `PyPi`_:: - - pip install dependency-injector - -Documentation -============= - -- The documentation is available on the `Read The Docs `_ - Frequently asked questions -========================== +-------------------------- What is the dependency injection? - dependency injection is a principle that decreases coupling and increases cohesion diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 470c7ace..a8b37b16 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -7,6 +7,11 @@ that were made in every particular version. From version 0.7.6 *Dependency Injector* framework strictly follows `Semantic versioning`_ +3.30.1 +------ +- Update README. +- Add one more example. + 3.30.0 ------ - Rework ``Movie Lister`` example. diff --git a/examples/di_demo2/config.yml b/examples/di_demo2/config.yml new file mode 100644 index 00000000..b6f36405 --- /dev/null +++ b/examples/di_demo2/config.yml @@ -0,0 +1,2 @@ +api_key: test-key +timeout: 5 \ No newline at end of file diff --git a/examples/di_demo2/demo.py b/examples/di_demo2/demo.py new file mode 100644 index 00000000..ccfccd97 --- /dev/null +++ b/examples/di_demo2/demo.py @@ -0,0 +1,39 @@ +from dependency_injector import containers, providers + + +class ApiClient: + + def __init__(self, api_key: str, timeout: int): + self.api_key = api_key + self.timeout = timeout + + +class Service: + + def __init__(self, api_client: ApiClient): + self.api_client = api_client + + +class Container(containers.DeclarativeContainer): + + config = providers.Configuration() + + api_client = providers.Singleton( + ApiClient, + api_key=config.api_key, + timeout=config.timeout, + ) + + service = providers.Factory( + Service, + api_client=api_client, + ) + + +if __name__ == '__main__': + container = Container() + container.config.from_yaml('config.yml') + + service = container.service() + + assert isinstance(service.api_client, ApiClient) diff --git a/src/dependency_injector/__init__.py b/src/dependency_injector/__init__.py index 15726916..34fb4b19 100644 --- a/src/dependency_injector/__init__.py +++ b/src/dependency_injector/__init__.py @@ -1,6 +1,6 @@ """Dependency injector top-level package.""" -__version__ = '3.30.0' +__version__ = '3.30.1' """Version number that follows semantic versioning. :type: str