Compare commits

...

1001 Commits

Author SHA1 Message Date
ZipFile
2c0aede4aa Merge branch 'release/4.48.1' 2025-06-20 10:49:54 +00:00
ZipFile
84a14f2ca7 Update changelog 2025-06-20 10:03:00 +00:00
ZipFile
0c58064a36 Make wiring inspect exclsuions extensible 2025-06-20 10:03:00 +00:00
ZipFile
eb74b1e9d0 Minor improvements for _cwiring.DependencyResolver code generation
* Remove KWPair
* Avoid type checks around _is_injectable
2025-06-20 10:03:00 +00:00
ZipFile
be7d25518d Add typing-extensions as a dependency for older Python versions 2025-06-20 10:03:00 +00:00
ZipFile
04b5907f21 Add warning on extra @inject 2025-06-20 10:03:00 +00:00
ZipFile
e6cc12762f Add support for resource_type in Lifespans 2025-06-18 21:58:00 +00:00
ZipFile
bf2ddbce32 Upgrade cibuildwheel 2025-06-16 10:51:39 +00:00
ZipFile
9d6994391f Merge branch 'release/4.48.0' 2025-06-16 09:03:49 +00:00
ZipFile
dd84a1b5d6 Bump version 2025-06-16 08:53:36 +00:00
ZipFile
31a98f7731 Update changelog 2025-06-16 08:51:10 +00:00
ZipFile
b261251b34 Fix Sphinx warning 2025-06-16 08:50:00 +00:00
Aran Moncusí Ramírez
4bfe64563e
Add resource type parameter to init and shutdown resources using specialized providers (#858) 2025-06-16 11:34:02 +03:00
AndrianEquestrian
b411807572
Add support for Fast Stream Depends (#898) 2025-06-16 10:37:31 +03:00
ZipFile
f2da51e0d4 Use typing_extensions.Self as fallback (fixes #902) 2025-06-05 16:26:40 +00:00
ZipFile
2293251986 Add docs for ASGI Lifespan support 2025-06-03 20:43:06 +00:00
ZipFile
1b4b3d349f Fix some more Sphinx warnings 2025-06-03 20:33:13 +00:00
ZipFile
d8e49f7dd5
Add support for async generator injections (#900) 2025-06-03 21:45:43 +03:00
ZipFile
c1f14a876a Expose null awaitables 2025-06-02 22:46:57 +00:00
ZipFile
c97a0cc515 Fix mypy warnings in dependency_injector.ext 2025-06-01 18:57:47 +00:00
ZipFile
0ada62acbf Add .editorconfig 2025-06-01 18:50:07 +00:00
ZipFile
67827a36d1 Fix mypy warnigns in containers.pyi 2025-06-01 18:46:30 +00:00
ZipFile
ceed6a8222 Add combine_as_imports = true isort option 2025-06-01 18:45:47 +00:00
ZipFile
6766ef3eba Remove __init__.pyi 2025-06-01 18:45:12 +00:00
ZipFile
a8914e54e0 Fix Sphinx warnings 2025-06-01 18:08:37 +00:00
ZipFile
cdd9ce5048 Add doc section on wire() caching 2025-06-01 17:51:04 +00:00
ZipFile
51c7db771d Fix csv newline handling in movie-lister example 2025-06-01 17:35:32 +00:00
ZipFile
a322584308 Add context manager support to Resource provider 2025-06-01 15:48:57 +00:00
ZipFile
4b3476cb48 Use cache in _fetch_reference_injections() 2025-05-31 12:31:54 +00:00
ZipFile
8460465b5e Merge branch 'release/4.47.1' 2025-05-30 19:52:18 +00:00
ZipFile
16f444b230 Bump version 2025-05-30 19:50:21 +00:00
ZipFile
1ae96e3eeb Use windows-2022 GHA image for building wheels 2025-05-30 19:44:47 +00:00
ZipFile
7fcf1ac7ad Make mypy --strict tests/typing passable 2025-05-30 19:31:44 +00:00
ZipFile
1271d0fa79 Add type info for _cwiring module 2025-05-30 19:29:11 +00:00
ZipFile
b9df88eea7 Fix typing for wiring marker 2025-05-30 19:28:49 +00:00
ZipFile
99489afa3f Strip debug symbols when building wheels 2025-05-28 20:35:04 +00:00
ZipFile
193249f7ec Merge branch 'release/4.47.0' 2025-05-28 19:09:56 +00:00
ZipFile
01349c43e1 Bump version 2025-05-28 19:05:05 +00:00
ZipFile
41ed07a210 Update changelog 2025-05-28 19:03:52 +00:00
ZipFile
8be79126ad Enable ABI3 for regular tests 2025-05-28 16:51:39 +00:00
ZipFile
dfee54932b Migrate to OIDC publishing 2025-05-28 13:50:02 +00:00
ZipFile
a61749c68d Enable ABI3 builds 2025-05-28 13:50:02 +00:00
ZipFile
14be69371b Limit ABI3 builds to CPython only 2025-05-28 13:50:02 +00:00
ZipFile
cfeb018ca7 Fix pytest-asyncio warning 2025-05-28 13:50:02 +00:00
ZipFile
183b2ae7ff Require Cython>=3.1.1 2025-05-28 13:50:02 +00:00
ZipFile
561ff46658 Add wheelhouse to .gitignore 2025-05-28 13:50:02 +00:00
ZipFile
49cc8ed827 Fix PyPy test runs in tox 2025-05-28 13:50:02 +00:00
ZipFile
383e95faed Fix file inclusion warnings from MANIFEST.in 2025-05-28 13:50:02 +00:00
Roman Mogylatov
e7e64f6ae0
Update coding-guide.mdc 2025-05-22 18:29:37 -04:00
Roman Mogylatov
f50cc95405 Add Cursor rules 2025-05-21 16:19:08 -04:00
Roman Mogylatov
8814db3fb3
Fix annotated attribute injection (#889)
* Add example for Annotated attribute injection for module/class attributes

* Fix attribute injection with Annotated types

* Add unit tests for Annotated attribute and argument injection in wiring

* Add .cursor to .gitignore

* Style: add blank lines between class definitions and attributes in annotated attribute example

* Docs: clarify and format module/class attribute injection for classic and Annotated forms

* Changelog: add note and discussion link for Annotated attribute injection support

* Fix nls

* Fix CI checks and Python 3.8 tests

* Fix PR issues

* Fix Python 3.8 tests

* Fix flake8 issues

* Fix: robust Annotated detection for wiring across Python versions

* Refactor: extract annotation retrieval and improve typing for Python 3.9 compatibility

* Update src/dependency_injector/wiring.py

Co-authored-by: ZipFile <zipfile.d@protonmail.com>

---------

Co-authored-by: ZipFile <zipfile.d@protonmail.com>
2025-05-21 16:13:37 -04:00
ZipFile
8bf9ed04c8
Update Cython to v3.1 (#887) 2025-05-18 13:55:06 +03:00
ZipFile
dbf86e4eb4
Do not override methods without patching (#886) 2025-05-18 12:17:54 +03:00
ZipFile
9a08bfcede
Drop Python 3.7 support (#885) 2025-05-18 12:06:33 +03:00
ZipFile
4ae79ac21f
Remove unused root property from ConfigurationOption (#875)
fixes #874
2025-04-07 14:57:45 +03:00
ZipFile
35bfafdfe2
Move pytest config to pyproject.toml (#876)
* Move pytest config to pyproject.toml

* Fix pytest warning
2025-04-07 14:57:13 +03:00
ZipFile
6685c5a141 Fix infinite loop with Closing+ConfigurationOption 2025-03-10 20:35:37 +00:00
ZipFile
57123cebaa Merge branch 'master' into develop 2025-03-02 12:37:21 +00:00
ZipFile
6e4794bab1
Remove code for EOL Python versions (#864) 2025-03-02 14:33:31 +02:00
ZipFile
f3b3b1baa4 Merge branch 'release/4.46.0' into master 2025-02-25 15:14:15 +00:00
ZipFile
9b66d4bf16 Bump version to v4.46.0 2025-02-23 17:22:13 +00:00
ZipFile
7d4ebecd19
Add option to disable env var interpolation in configs (#861) 2025-02-23 19:01:01 +02:00
ZipFile
09efbffab1
Fix Closing dependency resolution (#852)
Co-authored-by: federinik <federico.tomasi@outlook.com>
Co-authored-by: jazzthief <mynameisyegor@gmail.com>
2025-02-23 18:31:34 +02:00
ZipFile
8b625d81ad
Use Annotated for DI in FastAPI examples (#853) 2025-02-23 18:21:31 +02:00
ZipFile
23acf01c15
Add support for inspect.iscoroutinefunction() in Coroutine provider (#830) 2025-02-23 18:20:38 +02:00
Martin Lafrance
0d6fdb5b78
Fix broken wiring of sync inject-decorated methods (#673)
Co-authored-by: Martin Lafrance <mlafrance@cae.com>
Co-authored-by: ZipFile <zipfile.d@protonmail.com>
2025-02-23 18:17:45 +02:00
Taein Min
2330122de6
Add support for typing.Annotated (#721) 2025-01-20 17:37:28 +02:00
ZipFile
29ae3e1337 Make flake8 config black-compatible 2025-01-18 17:39:07 +00:00
ZipFile
50643e0dfb Run black 2025-01-18 17:02:55 +00:00
ZipFile
3893e1df81 Use native GHA ubuntu-24.04-arm image for building wheels 2025-01-16 19:15:49 +00:00
ZipFile
0fd35baee6 Use ubuntu-24.04 GHA image 2025-01-16 19:13:11 +00:00
Ilya Kazakov
3df95847d5
[movie-lister] Added test fixture and updated documentation (#747)
* test: add fixture for finder mock

* docs: update tests code example, emphasize-lines & test coverage report results
2025-01-12 15:46:29 +02:00
ZipFile
6d9d34c0f6 Add test case for Provider.provider type propagation 2025-01-12 12:18:21 +00:00
Philip Bjorge
de50666a13
fix: type provider (#744) 2025-01-12 14:14:12 +02:00
ZipFile
ccbd5bbb80 Migrate CI pipeline to actions/upload-artifact@v4 2025-01-08 13:07:04 +00:00
Philip Bjorge
00326e9a22
fix: type propogation through provided (#733)
Co-authored-by: Gonzalo Martinez <gonzarmv@gmail.com>
2025-01-08 13:31:00 +02:00
Roman Mogylatov
46646b1acf Merge branch 'release/4.45.0' into master 2025-01-05 15:20:12 -05:00
Roman Mogylatov
9f38db6ef3 Bump version to 4.45.0 2025-01-05 15:19:57 -05:00
Roman Mogylatov
9f4e2839d2
Remove unused imports from the starlette extension (#846) 2025-01-05 14:57:55 -05:00
ZipFile
41e18dfa90
Add Starlette lifespan handler implementation (#683) 2025-01-05 14:39:26 -05:00
František Trebuňa
f9db578c59
🎨 Raise exception instead of hiding it in finally (#845) 2025-01-05 14:33:09 -05:00
ZipFile
d82d9fb822
Improve debugability of deepcopy errors (#839) 2025-01-01 21:22:29 +02:00
ZipFile
3ba4704bc1 Remove six 2024-12-14 13:24:28 +00:00
JC (Jonathan Chen)
aa56b70dc8
docs: fix grammar (#709) 2024-12-09 10:54:30 +02:00
ZipFile
7f586246b4
Update examples (#838) 2024-12-08 18:53:29 +02:00
ZipFile
87741edb53
Upgrade testing deps (#837) 2024-12-08 18:53:08 +02:00
Roman Mogylatov
be7abb3ec7 Merge branch 'release/4.44.0' into master 2024-12-07 13:44:32 -05:00
ZipFile
15400dea7d
Fix sdist build for publishing (#836) 2024-12-07 13:42:27 -05:00
Roman Mogylatov
704e36a642 Merge branch 'release/4.44.0' into master 2024-12-07 11:52:05 -05:00
Roman Mogylatov
83d71acb70 Bump version to 4.44.0 2024-12-07 11:51:44 -05:00
ZipFile
c61fc16b8d
Yet another Pydantic 2 support (#832)
* Add support for Pydantic v2 settings

* Configure pipeline to run tests against different pydantic versions

* Update Pydantic docs and examples for v2

* Fix compatibility with httpx v0.27.0
2024-12-07 11:38:08 -05:00
Roman Mogylatov
cab75cb9c7 Update changelog 2024-11-10 00:05:25 -05:00
ZipFile
494c457643
PEP-517 (#829)
* Convert to PEP-517 project

* Move pylint and coverage configs to pyproject.toml

* Remove autogenerated C files
2024-11-10 00:01:30 -05:00
Roman Mogylatov
abf2a2577c Merge branch 'release/4.43.0' into master 2024-11-04 00:03:25 -05:00
Roman Mogylatov
3777a947ea Update version to 4.43.0 2024-11-04 00:02:52 -05:00
Roman Mogylatov
c92129dcb0
Add support for Python 3.13 (#828)
* Update tests pipeline and setup.py

* Update tox coverage command

* Add setuptools to the dev requirements file

* Enforce coverage version in tox

* Leave coveralls CI/CD job on Python 3.12 because coveralls 4.0.1 doesn't support Python 3.13

* Update changelog and publishing jobs
2024-11-04 00:01:28 -05:00
Roman Mogylatov
37486900cd Add ZipFile to the list of contributors and update changelog 2024-11-03 21:01:45 -05:00
Roman Mogylatov
9071583981 Pin Cython version 2024-11-03 20:55:53 -05:00
ZipFile
595daebd3a
Migrate to Cython3 (#813)
* Fix asyncio tests

* Convert class-private attributes to just private

* Upgrade to Cython 3

* Regenerate C files

* Fix tox coverage report
2024-11-03 20:48:40 -05:00
Roman Mogylatov
13a7ef609b Merge branch 'release/4.42.0' into master 2024-09-09 22:24:12 -04:00
Roman Mogylatov
7a88a8ee8d Update version 2024-09-09 22:23:27 -04:00
Roman Mogylatov
938091b6ea Add Github Sponsors button 2024-09-09 22:23:19 -04:00
Roman Mogylatov
4bda5105c2 Remove obsolete disqus javascript file 2024-09-09 22:22:09 -04:00
Roman Mogylatov
46034cbeb1 Update the copuright in the docs 2024-09-09 21:53:37 -04:00
Roman Mogylatov
39ac098ca2 Fix the Disqus comment widget 2024-09-09 21:52:11 -04:00
Roman Mogylatov
f54604fc14 Fix the bug in the docs step of the publishing job 2024-08-08 21:29:02 -04:00
Roman Mogylatov
2c998b8448 Merge branch 'release/4.42.0b1' into master 2024-08-07 22:11:07 -04:00
Roman Mogylatov
5697f1d5d8 Update macos version in the publishing job 2024-08-07 22:10:03 -04:00
Roman Mogylatov
086d82f13d Merge branch 'release/4.42.0b1' into master 2024-08-07 21:22:25 -04:00
Roman Mogylatov
3375436eb3 Remove Python 3.13 builds from the publishing job 2024-08-07 21:21:36 -04:00
Roman Mogylatov
fec2b08210 Merge branch 'release/4.42.0b1' into master 2024-08-07 21:04:56 -04:00
Roman Mogylatov
8a44027f3d Update cibuildwheel to version 2.20.0 2024-08-07 21:04:37 -04:00
Roman Mogylatov
f56453f59f Merge branch 'release/4.42.0b1' into master 2024-08-07 20:51:40 -04:00
Roman Mogylatov
1b9e079524 Add explicit setuptools installation to the publishing job 2024-08-07 20:48:41 -04:00
Roman Mogylatov
b1a3a69428 Merge branch 'release/4.42.0b1' into master 2024-08-06 22:52:17 -04:00
Roman Mogylatov
a8b54423dc Update version to 4.42.0b1 2024-08-06 22:51:59 -04:00
Roman Mogylatov
3e56fef461 Update version to 4.42.0b 2024-08-06 22:45:40 -04:00
Roman Mogylatov
5d1e5ee485 Update the year in the licensing file 2024-08-06 22:45:21 -04:00
Roman Mogylatov
f7c6cb2647 Add Anton Petrov to CONTRIBUTORS.rst 2024-08-06 22:44:57 -04:00
Roman Mogylatov
a5166bf591
Add Python 3.12 Support (#752) (#765)
* Add Python 3.12 Support (#752)

* Ignore .vscode

* Python 3.12 Support

* Change base python to 3.12 and pin pydantic to V1

* all tests passed

* ci: change default python to 3.12

* remove legacy python versions

* annotate pydantic models for tests

* Update publishing pipeline to use Python 3.12

* Test environment updates

* Update Cython to the latest prior 3.0 version and remove tracing from CI/CD

* Give up using editable tox installation in the coverage job

* Add mypy test fixes

* Remove tracing from the coverage job

* Fix typing test

* Remove PyPy 2.7

* Fix typing test

* Fix the typing issue with pydantic

* Remove pypy 3.9

* Fix the typing issue with mypy

* Update pydantic version to the latest from 1.x

* Update scipy deprecation warning filter

* Fix the tox job running coveralls

* Update changelog

---------

Co-authored-by: Anton Petrov <anton.a.petrov@gmail.com>
2024-08-06 22:41:24 -04:00
Roman Mogylatov
98d5867743 Add a link to my profile (#806) 2024-08-06 21:28:50 -04:00
Roman Mogylatov
68da747ce0
Add a link to my profile (#806) 2024-08-06 21:27:23 -04:00
Roman Mogylatov
cc2304e46e Merge branch 'release/4.41.0' into master 2022-12-18 22:14:24 -05:00
Roman Mogylatov
4bfdf89142 Bump version 2022-12-18 22:14:00 -05:00
Roman Mogylatov
659d242503 Update builds badge 2022-12-18 22:12:38 -05:00
Roman Mogylatov
6b13b6dbaf Update line length to 120 2022-12-18 22:04:03 -05:00
Roman Mogylatov
d3320f5f06 Fix typing in wiring 2022-12-18 22:02:11 -05:00
Roman Mogylatov
31c1f7c2d6 Update setup.py 2022-12-18 21:59:31 -05:00
Roman Mogylatov
d0c8f328b3 Update changelog 2022-12-18 21:52:32 -05:00
Jamie Stumme
3b76a0d091
Allow Closing to detect dependent resources (#636) 2022-12-18 21:49:23 -05:00
Roman Mogylatov
a79ea1790c Update custom provider docs formatting 2022-12-18 21:43:02 -05:00
Kirill Shershen
781d3b9c4c
fixed bug in windows build with default charset (#635)
Co-authored-by: kirill-shershen <kirill.shershen@alao.ch>
2022-12-18 21:42:23 -05:00
thatguysimon
6f491a6cae
Explicitly mention the required usage of "memo" (#598) 2022-12-18 21:38:12 -05:00
Roman Mogylatov
88a2b96102 Update FastAPI + Redis example 2022-12-18 21:35:43 -05:00
Yan
f0d9eda566
Update aioredis to 2.0.1 (#613)
* Update aioredis to 2.0.1

* Rearranged aioredis.from_url parameters
2022-12-18 21:27:36 -05:00
Roman Mogylatov
55f81bd754 Update changelog 2022-12-18 21:25:16 -05:00
Eugene Brodsky
a9cd0de886
(setup) fix install crash on non-utf8 systems (#644)
fixes https://github.com/ets-labs/python-dependency-injector/issues/643
2022-12-18 21:23:24 -05:00
Roman Mogylatov
aaff333f01
Python 3.11 Support (#647)
* Update tests

* Enable tests on 3.11

* Fix coverage config in tox.ini

* feat: re cythonize to support python 3.11 (#646)

* feat: re cythonize to support python 3.11

* misc: added tox env for python 3.11

* misc: add classifiers for python 3.11

* fix: skip tests for removed functions

* misc: CI updates for python 3.11

Co-authored-by: Roman Mogylatov <rmogilatov@gmail.com>

* Update tests and linters job

* Update test skip decorators

* Fix tox.ini

* Update 3.10 to be explicit string literal

* Move pypy3 to legacy job

* Fix error in resourse typing test

* Update publishing job

* Update actions and setup-python versions

* Update changelog

* Update pypy

* Update tox.ini with new pypy versions

* Update publishing job

* Update actions/upload-artifact@v3

* Update ubuntu to 22.04 on docs publishing job

* Update actions/download-artifact@v3 and pypa/gh-action-pypi-publish@release/v1

Co-authored-by: Gen Xu <xgbarry@gmail.com>
2022-12-18 21:09:14 -05:00
Roman Mogylatov
3858cef657 Merge branch 'release/4.40.0' into master 2022-08-03 21:20:52 -04:00
Roman Mogylatov
8cf86826eb Bump version to 4.40.0 2022-08-03 21:20:38 -04:00
Roman Mogylatov
6f859e4aa2
(#454) (#597) Fix @inject + @wraps, refactor patched callables registry and injections storage principles (#610)
* Refactor patched callables registry and injections storage principles

* Rename properties of PatchedRegistry

* Add typing improvements in wiring module

* Add __slots__ for PatchedAttribute

* Minor code style fixes

* Add test

* Rename test

* Update typing in test

* Make minor style fixes to test

* Update changelog

* Add documentation on the @inject decorator
2022-07-26 21:37:15 -04:00
Roman Mogylatov
0668295543 Fix code layout in tests/unit/schema/test_integration_py36.py 2022-07-19 20:33:43 -04:00
Roman Mogylatov
142b91921a
Upgrade Cython to 0.29.30 (#605) 2022-07-10 21:23:25 -04:00
Roman Mogylatov
753e863d02
Add `Configuration.from_json()` method (#602)
* Add implementation and tests

* Refactor naming in configuration fixtures

* Add typing for .from_json()

* Move get/set_ini_files() methods upper

* Add init implementation and tests

* Refactor typing tests

* Add examples

* Add docs

* Update docs index and readme

* Update changelog
2022-07-10 21:08:45 -04:00
Roman Mogylatov
14b5ddae4f Update pytest configuration 2022-07-02 15:11:25 -04:00
Roman Mogylatov
bf356ec565 Update wording in introduction docs 2022-04-17 10:55:17 -04:00
Roman Mogylatov
9bc11a7828 Improve wording in docs 2022-04-16 22:29:19 -04:00
Roman Mogylatov
a0bb7c4ede Update changelog 2022-04-16 21:46:01 -04:00
Roman Mogylatov
450407bf7a Update year 2021 -> 2022 2022-04-16 21:39:47 -04:00
Roman Mogylatov
4666a15092 Update copyright year 2022-04-16 21:35:03 -04:00
Illia Volochii
daca85d555
Fix a few issues in the introduction (#580)
* Fix a statement about coupling and cohesion that is not always true

https://enterprisecraftsmanship.com/posts/cohesion-coupling-difference/#_types_of_code_from_a_cohesion_and_coupling_perspective

* Fix a typing issue in an example

`ApiClient` expects timeout to be an integer (based on a type hint), but `os.getenv` returns a string when `TIMEOUT` is set.

* Specify the `None` return type where it is missed

* Fix typing issues in some other places

* Edit a statement about coupling and cohesion

Co-authored-by: Roman Mogylatov <rmogilatov@gmail.com>

Co-authored-by: Roman Mogylatov <rmogilatov@gmail.com>
2022-04-16 21:29:35 -04:00
Roman Mogylatov
20bf3c0a01 Pin jinja2 2022-03-30 00:14:25 -04:00
Roman Mogylatov
4188f721d6 Merge branch 'release/4.39.1' into master 2022-03-29 22:52:00 -04:00
Roman Mogylatov
cfed30cf07 Hotfix issue #574, bump version to 4.39.1 2022-03-29 22:51:40 -04:00
Roman Mogylatov
13cae77d57 Fix docs publishing error "The unauthenticated git protocol on port 9418 is no longer supported." 2022-03-28 00:33:48 -04:00
Roman Mogylatov
8b0745d43e Merge branch 'release/4.39.0' into master 2022-03-27 22:22:02 -04:00
Roman Mogylatov
93c8cbc83b Bump version to 4.39.0 2022-03-27 22:21:51 -04:00
Roman Mogylatov
77b5cdebd3
Optimization r1 (#571)
* Add isfuture() and iscoroutine() optimization

* Apply async mode optimization

* Wiring changes

* Add optimization for wiring of async coroutines

* Remove unused imports

* Update changelog

* Refactor async mode checks
2022-03-27 22:20:05 -04:00
Roman Mogylatov
f0c55cda22 Fix a typo 2022-03-27 14:23:35 -04:00
Roman Mogylatov
f00fa16bd0 Update changelog 2022-03-27 14:23:27 -04:00
Roman Mogylatov
c2877777af Refactor + add tests to #569 2022-03-27 14:18:46 -04:00
Vlad Fisher
8fe00bcff0
569 fix numpy typing wiring (#570)
* change erroneous issubclass call to isinstance

* import numpy.typing in tests

* better subclass check

* fix return
2022-03-27 14:11:04 -04:00
Roman Mogylatov
c26b260c73 Merge branch 'release/4.38.0' into master 2022-01-30 23:28:11 -05:00
Roman Mogylatov
ad0d430229 Bump version to 4.38.0 2022-01-30 23:27:58 -05:00
Roman Mogylatov
0235d68265 Refactor string imports 2022-01-30 23:19:09 -05:00
Roman Mogylatov
86df7f91f6
531 Provider import from string (#555)
* Implement string imports for Factory, Callable, Singletons, and Resource

* Refactor the implementation

* Add tests

* Update tests to pass on Python 2

* Update typing and add typing tests

* Update changelog

* Update docs
2022-01-30 23:16:55 -05:00
Roman Mogylatov
38ca1cdeed Fix #550 2022-01-28 23:12:08 -05:00
Roman Mogylatov
8dc3dd2f09 Update quotes in Cython and Python modules 2022-01-16 20:32:42 -05:00
Roman Mogylatov
a38ca647c3 Update quotes in typing stubs 2022-01-16 19:46:18 -05:00
Roman Mogylatov
d4933baec1 Update logo, v4 2022-01-16 18:39:36 -05:00
Roman Mogylatov
742e73af1a
Aggregate provider (#544)
* Add implementation and typing stubs

* Add tests

* Add typing tests

* Refactor FactoryAggregate

* Update changelog

* Add Aggregate provider docs and example

* Update cross links between Aggregate, Selector, and FactoryAggregate docs

* Add wording improvements to the docs
2022-01-09 21:45:20 -05:00
Roman Mogylatov
cfadd8c3fa
Add config.from_env(as_=...) (#541)
* Add implementation and typing stub

* Add unit tests

* Update demo example

* Add typing tests

* Update changelog

* Update docs

* Add tests for an empty environment variable

* Improve wording in di_in_python.rst

* Update wording in changelog and docs

* Update doc blocks
2021-12-20 23:46:51 +01:00
Roman Mogylatov
cc17052acc Fix mypy issues 2021-11-29 00:13:17 +02:00
Roman Mogylatov
7238482402 Add .providers attribute and .set_providers() method to FactoryAggregate provider 2021-11-26 19:50:19 +03:00
Roman Mogylatov
541131e338 Merge branch 'release/4.37.0' into master 2021-10-31 21:12:54 -04:00
Roman Mogylatov
72d0e2610d Add announce of Python 3.5 support dropping 2021-10-31 21:00:28 -04:00
Roman Mogylatov
0b3bcf334e Bump version to 4.37.0 2021-10-31 20:50:16 -04:00
Roman Mogylatov
99d858e2fb Upgrade Cython to 0.29.24 2021-10-31 20:48:23 -04:00
Roman Mogylatov
fe01ad41d9
Update examples to use config __init__ args (#527)
* Update application-single-container example

* Update application-multiple-containers example

* Update decoupled-packages example

* Update movie lister example

* Update CLI tutorial

* Update sanic example

* Update sanic example with wiring_config

* Update fastapi example

* Update fastapi-simple example

* Update fastapi-sqlalchemy example

* Update flask-blueprints example

* Update flask example and tutorial

* Update aiohttp example and tutorial

* Update asyncio-daemon example and tutorial
2021-10-31 20:31:39 -04:00
Roman Mogylatov
6030950596
Configuration(pydantic_settings=[...]) (#525)
* Add implementation

* Update changelog

* Fix deepcopy()

* Add example

* Add tests

* Add docs
2021-10-26 21:08:47 -04:00
Roman Mogylatov
34902db86e
Configuration(ini_files=[...]) (#524)
* Update changelog

* Add implementation

* Add tests

* Add more tests and example

* Update changelog

* Update documentation
2021-10-26 20:27:11 -04:00
Roman Mogylatov
b16b190ff7
Configuration(yaml_files=[...]) (#522)
* Add provider changes and tests

* Move config test fixtures

* Fix issue with explicit providing of envs_required=False for configuration from_*()

* Implement container API

* Increase priority of overriding from context

* Add docs and example

* Update changelog

* Update changelog
2021-10-23 21:46:50 -04:00
Roman Mogylatov
b97862cb9f
Python 3.10 (#520)
* Add GA test and linter jobs

* Remove not used async run() functions from tests

* Update aiohttp ext test

* Add botocore warning ignores

* Update changelog

* Update publishing job config for testing

* Publishing test #1

* Update GA tests-and-linters job to use latest ubuntu for tests

* Update publishing GA job
2021-10-20 12:10:05 -04:00
Roman Mogylatov
94aca21fb8
Pytest migration (#519)
* Add pytest and pytest-asyncio to the requirements

* Update aiohttp ext test

* Update setup.cfg

* Update tox.ini

* Add pytest to the tox requirements

* Update tox.ini

* Move configuration to tox.ini

* Add pytest configs

* Rename pytest-py34-py35.ini -> pytest-py35.ini

* Update config file paths

* Update makefile

* Migrate common tests to pytest

* Migrate FastAPI and Flask wiring tests

* Rename flask and fastapi wiring test files

* Move wiring autoloader tests

* Add pytest-asyncio to the tox.ini

* Migrate wiring async injection tests

* Migrate main wiring tests

* Migrate wiring string module and package names tests

* Migrate wiring config tests

* Migrate misc wiring tests

* Update tests structure

* Migrate misc wiring tests

* Refactor container.from_schema() API tests

* Migrate container.from_schema() integration tests

* Rename schema samples

* Update sample imports

* Migrate container tests

* Refactor container tests

* Migrate container self tests

* Migrate container instance tests

* Migrate container custom string attribute name tests

* Migrate container async resource tests

* Fix py2 container tests

* Migrate container cls tests

* Migrate container class custom string cls as atrribute name tests

* Migrate ext.aiohttp tests

* Migrate ext.flasks tests

* Update ext package tests doc block

* Migrate provider utils tests

* Migrate Factory async mode tests

* Migrate async tests

* Rename common test module

* Refactor asserts in provider tests

* Migrate factory tests

* Migrate selector provider tests

* Migrate object provider tests

* Migrate self provider tests

* Migrate delegate provider tests

* Migrate provider tests

* Migrate dependency provider tests

* Migrate dependencies container provider tests

* Fix warnings

* Migrate list provider tests

* Migrate dict provider tests

* Migrate callable tests

* Migrate injection tests

* Migrate container provider tests

* Migrate coroutine providers

* Migrate traversal tests

* Migrate resource tests

* Migrate configuration tests

* Migrate provided instance provider tests

* Update doc blocks and imports

* Migrate singleton tests

* Update changelog and cosmetic fixes
2021-10-18 16:19:03 -04:00
Roman Mogylatov
4cc4ca9188
Drop Python 3.4 support (#518)
* Update gitignore

* Drop Python 3.4 support

* Update change log

* Fix typo in changelog
2021-10-12 12:16:49 -04:00
Roman Mogylatov
284dee6e58
Add with support for container.override_providers() (#517)
* Add implementation, tests, and typing stub

* Update documentation

* Update changelog
2021-10-06 21:36:41 -04:00
Roman Mogylatov
73a43e6191
Wiring config (#516)
* Implement POC

* Implement concept with WiringConfiguration object

* Update changelog

* Add docs

* Update changelog
2021-10-03 20:35:48 -04:00
Roman Mogylatov
08ea99759d Update versions 2021-09-30 20:36:42 -04:00
Roman Mogylatov
f82a6b5445 Update versions in the docs 2021-09-30 20:18:23 -04:00
Roman Mogylatov
1e198a3ebd Add disqus comments to typing docs page 2021-09-30 20:15:57 -04:00
Roman Mogylatov
4f977c7cf0 Update quotes in docs conf 2021-09-30 20:13:26 -04:00
Roman Mogylatov
8ade2b7839 Update quotes in tests 2021-09-30 20:09:42 -04:00
Roman Mogylatov
0b1e214135 Fix flast wiring test 2021-09-30 19:32:18 -04:00
Roman Mogylatov
98f036e14c Update quotes in the docs 2021-09-30 19:26:04 -04:00
Roman Mogylatov
023d766267 Update django example 2021-09-30 19:19:34 -04:00
Roman Mogylatov
196d86f4b3 Update quotes in factory-patterns example 2021-09-30 19:09:47 -04:00
Roman Mogylatov
6b4c7e50b5 Update fastapi-simple example 2021-09-30 19:08:49 -04:00
Roman Mogylatov
3c52756d3f Update quotes in fastapi-sqlalchemy example 2021-09-30 19:05:57 -04:00
Roman Mogylatov
274d1fe53b Update quotes in password-hashing example 2021-09-30 19:02:23 -04:00
Roman Mogylatov
8bea62eeee Update quotes in use-cases example 2021-09-30 19:01:31 -04:00
Roman Mogylatov
b64c9b7a05 Update sanic example 2021-09-30 18:59:09 -04:00
Roman Mogylatov
31bed0651f Update sanic example 2021-09-30 18:56:29 -04:00
Roman Mogylatov
e670377bb3 Update quotes in fastapi example 2021-09-30 16:55:50 -04:00
Roman Mogylatov
a9173496b4 Update quotes in commands-and-handlers example 2021-09-30 16:53:27 -04:00
Roman Mogylatov
02b9793189 Fix boto3 example 2021-09-30 16:02:49 -04:00
Roman Mogylatov
4a52595a9d Update quotes in boto3 example 2021-09-30 15:57:34 -04:00
Roman Mogylatov
c92a941fe5 Update quotes in flask tutorial and example 2021-09-30 15:55:10 -04:00
Roman Mogylatov
7e794c41dd Update quotes in aiohttp tutorial 2021-09-30 15:44:15 -04:00
Roman Mogylatov
93dad6bbd0 Update quotes in aiohttp example 2021-09-30 15:37:21 -04:00
Roman Mogylatov
320d837bea Update quotes in provider examples 2021-09-30 15:32:21 -04:00
Roman Mogylatov
d827f93816 Update quotes in container examples 2021-09-30 15:16:17 -04:00
Roman Mogylatov
b3732281a1 Update changelog 2021-09-30 15:08:22 -04:00
Roman Mogylatov
7d160cb4a5
Wiring with string module names (#515)
* Update main example

* Updating wiring module

* Update wiring test case name

* Implement string imports for wiring

* Update example

* Refactor implementation

* Update front example

* Fix a typo in README

* Update wiring docs

* Update single container example

* Update multiple containers example

* Update quotes in multiple containers example

* Update quotes in single container example

* Update decoupled-packages example

* Update single and multiple containers example

* Update quotes

* Update fastapi+redis example

* Update resource docs

* Update quotes in CLI tutorial

* Update CLI application (movie lister) tutorial

* Update monitoring daemon example

* Update python version in asyncio daemon example

* Update asyncio daemon tutorial

* Update quotes in wiring docs

* Update wiring docs
2021-09-30 15:03:19 -04:00
Roman Mogylatov
258c55dd22 Merge branch 'release/4.36.2' into master 2021-09-28 14:59:28 -04:00
Roman Mogylatov
0b5987bf84 Bump version to 4.36.2 2021-09-28 14:59:11 -04:00
Roman Mogylatov
cf039a0c2b Merge branch 'release/4.36.1' into master 2021-09-28 14:51:54 -04:00
Roman Mogylatov
980914c2f7 Bump version to 4.36.1 2021-09-28 14:51:39 -04:00
Roman Mogylatov
5c7bdf4fc6 Update docs author 2021-09-28 14:50:45 -04:00
Roman Mogylatov
4733aad44e
Fix provide issue (#514) 2021-09-25 15:36:48 -04:00
Roman Mogylatov
d8aa70c70b
Update changelog.rst 2021-09-16 12:55:14 -04:00
whysage
8377f2a82d
Fix boto3 url (#511) 2021-09-16 12:52:58 -04:00
Roman Mogylatov
cc4235257c Update changelog 2021-09-12 20:15:03 -04:00
Rajan Jha
ff5b81fecb
Fixed a typo in Factory provider docs "service.add_attributes(clent=client)" #499 (#504) 2021-09-12 20:10:25 -04:00
Roman Mogylatov
cef6d35cfd Merge branch 'release/4.36.0' into master 2021-08-25 12:06:37 -04:00
Roman Mogylatov
902913ccff Bump version to 4.36.0 2021-08-25 12:06:22 -04:00
Roman Mogylatov
14d8ed909b
FactoryAggregate - non string keys (#496)
* Improve FactoryAggregate typing stub

* Add implementation, typing stubs, and tests

* Update changelog

* Fix deepcopying

* Add example

* Update docs

* Fix errors formatting for pypy3
2021-08-25 10:20:45 -04:00
Roman Mogylatov
6af818102b Update list of contributors 2021-08-23 21:27:24 -04:00
Roman Mogylatov
e0825041b0 Update changelog 2021-08-23 21:25:32 -04:00
Thiago Hiromi
b4df3dd2c9
Fix type annotations for .provides (#491)
* Fix type annotations for .provides

* Fix type hinting for .provides

as @rmk135 suggested
2021-08-23 21:24:36 -04:00
Roman Mogylatov
cf2861c4b4 Update changelog 2021-08-23 21:14:22 -04:00
Roman Mogylatov
49e2cc75c2 Make #492 follow-up fix of configuration provider docs for environment variables interpolation 2021-08-23 21:07:58 -04:00
Felipe Rubio
eda67e42d0
Fix yaml configuration-envs-interpolation examples (#494)
the interpolation of the environment variables in yaml is wrong, I have changed the example from {$ ENV_VAR} to $ {ENV_VAR}
2021-08-23 21:01:45 -04:00
Roman Mogylatov
ea9aa2370e Update changelog 2021-08-23 21:00:47 -04:00
Roman Mogylatov
36bfd2ed58
Improve resource subclasses typing and make shutdown definition optional (#492)
* Improve resource subclasses typing and make shutdown definition optional

* Update mypy tests
2021-08-23 20:54:17 -04:00
Roman Mogylatov
83c2af0e7e Fix resource subclass abc tests on Python 3.7 2021-08-16 18:27:42 -04:00
Roman Mogylatov
1163ac59d4 Return ABCMeta class for resource classes and add tests for abc 2021-08-16 18:19:40 -04:00
Roman Mogylatov
4286013ca0
Remove generic meta class from resource and async resource classes (#490)
* Remove generic meta class from resource and async resource classes

* Add link to the issue into the tests

* Update changelog
2021-08-16 10:05:50 -04:00
Roman Mogylatov
48df949cd5 Merge branch 'release/4.35.3' into master 2021-08-11 21:25:25 -04:00
Roman Mogylatov
9637d97d48 Bump version to 4.35.3 2021-08-11 21:25:18 -04:00
Roman Mogylatov
c4639e555e Add typing fix for container.override_providers() 2021-08-11 21:24:34 -04:00
Roman Mogylatov
7b19fa0964
477 Containers @copy fix and refactoring (#485)
* Rename local variables

* Make code layout enhancements

* Add fix and tests

* Add more refactoring

* Update changelog
2021-08-11 21:18:37 -04:00
Roman Mogylatov
cde7dee4b3 Merge branch 'release/4.35.2' into master 2021-08-06 16:50:53 -04:00
Roman Mogylatov
5acde87a6e Bump version to 4.35.2 2021-08-06 16:50:42 -04:00
Roman Mogylatov
7bdcc33eda Update wiring to support modules provided as packages 2021-08-06 15:56:24 -04:00
Roman Mogylatov
b4ddf61939 Merge branch 'release/4.35.1' into master 2021-08-05 17:05:43 -04:00
Roman Mogylatov
f376628dfa Bump version to 4.35.1 2021-08-05 17:05:17 -04:00
Roman Mogylatov
384117db9c Update declarative container to support custom string types 2021-08-05 17:01:53 -04:00
Roman Mogylatov
06f9855140
Update types and add tests (#480) 2021-08-05 16:52:08 -04:00
Roman Mogylatov
547b7fd844 Merge branch 'release/4.35.0' into master 2021-07-29 16:41:36 -04:00
Roman Mogylatov
04117938d2 Bump version to 4.35.0 2021-07-29 16:41:23 -04:00
Roman Mogylatov
c23a48c28e Update six upper bound to 1.16.0 2021-07-29 16:18:45 -04:00
Roman Mogylatov
98a4b06a12 Merge branch 'release/4.34.2' into master 2021-07-24 16:35:10 -04:00
Roman Mogylatov
c19969a6ed Bump version to 4.34.2 2021-07-24 16:33:16 -04:00
Roman Mogylatov
aa251a44ba Fix reverse shutdown order bug in container.shutdown_resources() 2021-07-24 16:32:44 -04:00
Roman Mogylatov
f44924f285 Merge branch 'release/4.34.1' into master 2021-07-20 18:48:39 -04:00
Roman Mogylatov
a126df4764 Bump version to 4.34.1 2021-07-20 18:48:23 -04:00
Roman Mogylatov
3d1bb5d7b3
432 resource shutdown order (#473)
* Add PoC

* Add tests for init and shutdown ordering

* Add circular dependencies breaker tests

* Refactoring and sync + async test

* Update changelog
2021-07-20 18:46:44 -04:00
Roman Mogylatov
54de3a9d2c Merge branch 'release/4.34.0' into master 2021-06-24 16:03:37 +03:00
Roman Mogylatov
6ffb98af67 Bump version to 4.34.0 2021-06-24 16:03:11 +03:00
Roman Mogylatov
ef049daae5
463 Config environment variables interpolation required and nones (#467)
* Make prototype with enterpolation before parsing

* Add test for option.from_yaml() with missing env not required

* Make some cosmetic changes to _resolve_config_env_markers()

* Add test for option.from_ini() missing envs not required

* Skip schema test cause it requires internet connection

* Add tests for .from_yaml() for config and config option

* Add tests for .from_ini() for config and config option

* Add example for os.environ.setdefault() and envs interpolation

* Add/update docs on environment variables interpolation

* Update changelog
2021-06-24 16:00:36 +03:00
Roman Mogylatov
9abf34cb88 Merge branch 'release/4.33.0' into master 2021-06-13 22:06:36 -04:00
Roman Mogylatov
31beb54979 Bump version to 4.33.0 2021-06-13 22:06:27 -04:00
Roman Mogylatov
dbbf5fdcf1
462 Config.from_value() (#465)
* Implement .from_value() method for config provider

* Add tests for config.from_value() method

* Add example for config.from_value()

* Add docs

* Update changelog
2021-06-13 22:05:29 -04:00
Roman Mogylatov
bbd623c719
459 Add default value for environment variable for yaml and ini config files (#461)
* Add tests for partial yaml interpolation

* Add tests for partial ini interpolation

* Add yaml config env defaults parsing

* Implement default interpolation for ini files

* Add tests for ini files env interpolation

* Update docs

* Update docs

* Update config docs keywords
2021-06-13 15:07:30 -04:00
Roman Mogylatov
585c717650 Merge branch 'release/4.32.3' into master 2021-05-20 18:12:09 -04:00
Roman Mogylatov
e06dd782cd Bump version to 4.32.3 2021-05-20 18:12:00 -04:00
Ngo Thanh Loi (Leonn)
c2a1351612
Fix typo (#456) 2021-05-20 17:58:15 -04:00
Roman Mogylatov
64574dff4d Merge branch 'release/4.32.2' into master 2021-04-26 22:11:08 -04:00
Roman Mogylatov
39fb88a0e9 Bump version to 4.32.2 2021-04-26 22:09:35 -04:00
Roman Mogylatov
eacb190907 Improve wiring fault tolerance 2021-04-26 22:07:48 -04:00
Roman Mogylatov
fcba4cc989 Merge branch 'release/4.32.1' into master 2021-04-25 17:37:19 -04:00
Roman Mogylatov
b4a23670c1 Fix Windows builds 2021-04-25 17:37:08 -04:00
Roman Mogylatov
ce157eeab9 Merge branch 'release/4.32.1' into master 2021-04-25 13:45:43 -04:00
Roman Mogylatov
0f3e170711 Bump version to 4.32.1 2021-04-25 13:45:34 -04:00
Roman Mogylatov
fab4e3e5be Merge branch 'release/4.32.0' into master 2021-04-18 21:47:56 -04:00
Roman Mogylatov
42deda7eb5 Bump version to 4.32.0 2021-04-18 21:47:47 -04:00
Roman Mogylatov
a34bd456e8 Update Cython to 0.29.22 2021-04-18 21:47:34 -04:00
RK
9cb8e60280
Feature: Context local provider (#442)
Co-authored-by: Rollo Konig Brock <rollo@b2c2.com>
2021-04-18 21:37:55 -04:00
Roman Mogylatov
155f598699 Merge branch 'release/4.31.2' into master 2021-03-30 14:02:22 -06:00
Roman Mogylatov
57b4913b9b Bump version to 4.31.2 and update changelog 2021-03-30 14:02:12 -06:00
Roman Mogylatov
664a6ca5d9 Add sonthonaxrk to the list of contributors 2021-03-30 14:01:22 -06:00
RK
9ed13a4023 Fix provider documentation (#440)
Make example more realistic.  This would break if you're running flask with multiple threads.
2021-03-30 13:59:06 -06:00
Roman Mogylatov
7b70f46601 Fix an issue with Dict provider non-string keys 2021-03-30 10:25:45 -04:00
Roman Mogylatov
d04596be73 Merge branch 'release/4.31.1' into master 2021-03-23 21:14:47 -04:00
Roman Mogylatov
37dd617260 Bump version to 4.31.1 2021-03-23 21:14:35 -04:00
Roman Mogylatov
1aef599606
Fix ThreadSafeSingleton synchronization issue (#434)
* Fix ThreadSafeSingleton synchronization issue

* Update changelog
2021-03-23 21:14:03 -04:00
Roman Mogylatov
fca9fd498c Merge branch 'release/4.31.0' into master 2021-03-20 21:42:57 -04:00
Roman Mogylatov
88455d10ff Bump version to 4.31.0 2021-03-20 21:42:40 -04:00
Roman Mogylatov
41e698f633
Fix configuration cache reset (#430)
* Implement fix

* Improve providers copying

* Add tests and implement cache reset for configuration option

* Update changelog

* Add link to the issue
2021-03-20 21:41:39 -04:00
Roman Mogylatov
f961ff536a
Schemas (#429)
* Add single container prototype

* Add multiple containers prototype

* Add integration tests

* Implement from_*() methods and add tests

* Prototype inline injections

* Add integration test for inline providers

* Refactor integration tests

* Add integration test for reordered schema

* Remove unused imports from tests

* Refactor schema module

* Update tests to match latest schemas

* Add mypy_boto3_s3 to the test requirements

* Add boto3 to the test requirements

* Add set_provides for Callable, Factory, and Singleton providers

* Fix warnings in tests

* Add typing stubs for Callable, Factory, and Singleton .set_provides() attributes

* Fix singleton children to have optional provides

* Implement provider to provider resolving

* Fix pypy3 tests

* Implement boto3 session use case and add tests

* Implement lazy initialization and improve copying for Callable, Factory, Singleton, and Coroutine providers

* Fix Python 2 tests

* Add region name for boto3 integration example

* Remove f-strings from set_provides()

* Fix schema flake8 errors

* Implement lazy initialization and improve copying for Delegate provider

* Implement lazy initialization and improve copying for Object provider

* Speed up wiring tests

* Implement lazy initialization and improve copying for FactoryAggregate provider

* Implement lazy initialization and improve copying for Selector provider

* Implement lazy initialization and improve copying for Dependency provider

* Implement lazy initialization and improve copying for Resource provider

* Implement lazy initialization and improve copying for Configuration provider

* Implement lazy initialization and improve copying for ProvidedInstance provider

* Implement lazy initialization and improve copying for AttributeGetter provider

* Implement lazy initialization and improve copying for ItemGetter provider

* Implement lazy initialization and improve copying for MethodCaller provder

* Update changelog

* Fix typing in wiring module

* Fix wiring module loader uninstallation issue

* Fix provided instance providers error handing in asynchronous mode

Co-authored-by: Roman Mogylatov <rmk@Romans-MacBook-Pro.local>
2021-03-20 13:16:51 -04:00
Roman Mogylatov
8cad8c6b65 Merge branch 'release/4.30.0' into master 2021-03-19 20:23:39 -04:00
Roman Mogylatov
9ea8709ed9 Bump version to 4.30.0 2021-03-19 20:23:20 -04:00
Roman Mogylatov
6c1b7cc677 Remove restriction to wire a dynamic container 2021-03-19 20:23:10 -04:00
Roman Mogylatov
ee89476db0 Merge branch 'release/4.29.2' into master 2021-03-08 16:33:46 -05:00
Roman Mogylatov
e42d7dc05e Bump version to 4.29.2 2021-03-08 16:33:32 -05:00
Roman Mogylatov
bbbed8972a
Wiring import fixes numpy scipy (#422)
* Add signature guards

* Fix flake8 errors and update changelog

* Fix slow numpy/scipy installs on pypy3
2021-03-08 16:32:34 -05:00
Roman Mogylatov
b3bcf60ced Merge branch 'release/4.29.1' into master 2021-03-05 20:20:10 -05:00
Roman Mogylatov
ed0b93bdbe Pin ubuntu to 18.04 for publishing jobs 2021-03-05 20:19:31 -05:00
Roman Mogylatov
d4ebb1b786
Remove unittest2 (#419)
* Remove unittest2 framework

* Skip a couple of tests on Python 2.7

* Update changelog
2021-03-05 20:17:28 -05:00
Roman Mogylatov
6b57ce9f15 Merge branch 'release/4.29.1' into master 2021-03-05 17:28:56 -05:00
Roman Mogylatov
dbad7949b0 Bump version to 4.29.1 2021-03-05 17:28:46 -05:00
Roman Mogylatov
22629544a4 Fix recursive copying issue in `Delegate` provider 2021-03-05 17:24:48 -05:00
Roman Mogylatov
c14ff96773 Remove legacy css file 2021-03-05 17:23:57 -05:00
Roman Mogylatov
2cab6c687a Add docs and example for `Factory.add_attributes()` method 2021-03-03 16:06:53 -05:00
Roman Mogylatov
f1a3ad0b82 Merge branch 'release/4.29.0' into master 2021-03-03 09:06:29 -05:00
Roman Mogylatov
3f026887bf Bump version to 4.29.0 2021-03-03 09:06:19 -05:00
Roman Mogylatov
1304e596d6
Container provider override API (#418)
* Implement override API

* Add tests

* Update changelog
2021-03-03 09:05:15 -05:00
Roman Mogylatov
2bf3601695
Singleton reset context (#417)
* Add implementation and typing stubs

* Make some refactoring and add tests

* Pin ubuntu version to 18.04

* Add docs and example

* Add changelog

* Add container docs
2021-03-03 08:28:10 -05:00
Roman Mogylatov
e0b0a1e968 Merge branch 'release/4.28.1' into master 2021-03-01 09:06:24 -05:00
Roman Mogylatov
e6a0973be3 Bump version to 4.28.1 2021-03-01 09:06:11 -05:00
Roman Mogylatov
346451819e Fix async mode mode exception handling issue in `Dependency` provider 2021-03-01 09:01:51 -05:00
Roman Mogylatov
26571e805a Fix links to `boto3` example 2021-03-01 08:28:22 -05:00
Roman Mogylatov
25c966f7af Merge branch 'release/4.28.0' into master 2021-02-28 21:08:59 -05:00
Roman Mogylatov
cc05b42200 Bump version to 4.28.0 2021-02-28 21:08:50 -05:00
Roman Mogylatov
da13341453
Wiring: attribute injections (#414)
* Add implementation

* Add tests for module and class

* Add tests for module and class for string ids

* Update tests with typing

* Add tests for invalid type of marker

* Add docs and the example

* Update changelog

* Fix Python 3.6 tests and flake8
2021-02-28 21:07:50 -05:00
Roman Mogylatov
c787ac2f63 Merge branch 'release/4.27.0' into master 2021-02-27 09:47:11 -05:00
Roman Mogylatov
48392beff2 Bump version to 4.27.0 2021-02-27 09:46:58 -05:00
Roman Mogylatov
73b8a4aac4
Introduce wiring inspect filter (#412)
* Introduce wiring inspect filter

* Upgrade exclusion filter

* Refactor wiring
2021-02-27 09:45:49 -05:00
Roman Mogylatov
6763ad2934 Update changelog 2021-02-25 17:02:01 -05:00
Shubhendra Singh Chauhan
4ac798014a
Integration: DeepSource (#407)
* Refactor unnecessary `else` / `elif` when `if` block has a `return` statement

* Remove unused imports

* Use literal syntax to create data structure

* revert "remove unused import"

* Create .deepsource.toml
2021-02-25 16:57:34 -05:00
Roman Mogylatov
9788a1888f Add `boto3` example 2021-02-25 11:06:08 -05:00
Roman Mogylatov
3cf14c139f Add @withshubh to the list of contributors 2021-02-25 09:52:24 -05:00
Roman Mogylatov
95b0356edc Update changelog 2021-02-25 09:51:33 -05:00
Shubhendra Singh Chauhan
43eb15ed65
fix: code quality issues (#406)
* Refactor unnecessary `else` / `elif` when `if` block has a `return` statement

* Remove unused imports

* Use literal syntax to create data structure

* revert "remove unused import"
2021-02-25 09:44:15 -05:00
Roman Mogylatov
5f6777db19 Add tests for `.as_float()` modifier usage with wiring 2021-02-23 10:20:04 -05:00
Roman Mogylatov
d3720bd6dd Merge branch 'release/4.26.0' into master 2021-02-21 10:35:42 -05:00
Roman Mogylatov
0149338bb6 Bump version to 4.26.0 2021-02-21 10:35:33 -05:00
Roman Mogylatov
a4a84bea54
Wiring by string id (#403)
* Add prototype implementation

* Implement wiring by string id

* Fix pydocstyle errors

* Refactor wiring module

* Fix flake8 errors

* Update changelog

* Fix flake8 errors

* Add example and docs
2021-02-21 10:34:28 -05:00
Roman Mogylatov
d9d811a4d4 Improve error message for `Dependency` provider missing attribute 2021-02-19 08:50:14 -05:00
Roman Mogylatov
0026f48cb6 Merge branch 'release/4.25.1' into master 2021-02-19 08:12:43 -05:00
Roman Mogylatov
e5017347c7 Bump version to 4.25.1 2021-02-19 08:11:18 -05:00
Roman Mogylatov
a85d89e6f2 Amend docs and add another example for `@containers.copy()` decorator 2021-02-19 08:11:05 -05:00
Roman Mogylatov
6a73b9d3fd Merge branch 'release/4.25.0' into master 2021-02-18 17:52:46 -05:00
Roman Mogylatov
a71154e05f Bump version to 4.25.0 2021-02-18 17:52:29 -05:00
Roman Mogylatov
2dc78a6875 Add new multiple containers example 2021-02-18 17:49:39 -05:00
Roman Mogylatov
990fd3a554 Add attributes forwarding for the `Dependency` provider 2021-02-18 17:49:23 -05:00
Roman Mogylatov
c0d1e48f7b Merge branch 'release/4.24.0' into master 2021-02-18 08:51:24 -05:00
Roman Mogylatov
1d588cf9f6 Bump version to 4.24.0 2021-02-18 08:51:11 -05:00
Roman Mogylatov
8806405f0f Add docs on @containers.copy() decorator 2021-02-18 08:38:35 -05:00
Roman Mogylatov
13aa5fa53d Refactor @containers.copy() decorator 2021-02-18 08:25:22 -05:00
Roman Mogylatov
64a7a18f79 Improve doc blocks in declarative_override_decorator.py example 2021-02-18 08:18:35 -05:00
Roman Mogylatov
c7ba58c0af Refactor async mode support in containers module 2021-02-18 08:17:05 -05:00
Roman Mogylatov
18051522d7 Merge branch 'release/4.23.5' into master 2021-02-17 11:32:44 -05:00
Roman Mogylatov
763d42d532 Bump version to 4.23.5 2021-02-17 11:31:54 -05:00
Roman Mogylatov
f9a2ffaad6 Merge branch 'release/4.23.4' into master 2021-02-17 10:08:57 -05:00
Roman Mogylatov
6c45eb4eee Bump version to 4.23.4 2021-02-17 10:08:43 -05:00
Roman Mogylatov
70bebf9075 Merge branch 'release/4.23.3' into master 2021-02-17 10:02:41 -05:00
Roman Mogylatov
24cfd13acb Bump version to 4.23.3 2021-02-17 10:02:20 -05:00
Roman Mogylatov
27d0e07718
Async mode awaitable fix (#400)
* Fix mistakenly processed awaitable objects

* Update changelog

* Replace __isawaitable() with __is_future_or_coroutine()

* Refactor async mode
2021-02-17 09:56:39 -05:00
Roman Mogylatov
6e59b4ab6f Merge branch 'release/4.23.2' into master 2021-02-16 12:28:13 -05:00
Roman Mogylatov
6402c5b6f1 Bump version to 4.23.2 2021-02-16 12:28:00 -05:00
Roman Mogylatov
de1181bdf7
Async mode fixes (#399)
* Fix double printing of exception when initializing resource causes error

* Improve async mode exceptions handling to prevent infinite hanging when exception occurs

* Improve async mode exceptions handling

* Update changelog

* Update tests
2021-02-16 12:26:23 -05:00
Roman Mogylatov
b2ea773c71 Merge branch 'release/4.23.1' into master 2021-02-15 18:13:21 -05:00
Roman Mogylatov
12d53c799d Bump version to 4.23.1 2021-02-15 18:13:01 -05:00
Roman Mogylatov
8cc2c1188b Fix issue #398 with FastAPI request importing 2021-02-15 17:47:03 -05:00
Roman Mogylatov
6c06548019 Merge branch 'release/4.23.0' into master 2021-02-15 09:13:00 -05:00
Roman Mogylatov
c28a4dc047 Bump version to 4.23.0 2021-02-15 09:12:46 -05:00
Roman Mogylatov
64d37efa37
Configuration provider aliases (#397)
* Add implementation, typing stubs, and tests

* Add docs and example

* Update changelog
2021-02-15 09:11:39 -05:00
Roman Mogylatov
93fa37728b Merge branch 'release/4.22.1' into master 2021-02-14 21:09:31 -05:00
Roman Mogylatov
ed0a413b67 Bump version to 4.22.1 2021-02-14 21:09:21 -05:00
Roman Mogylatov
368f50f0ba Fix typo in FastAPI + SQLAlchemy example docs 2021-02-14 21:08:19 -05:00
Roman Mogylatov
d9e946ff56 Pin Sphinx version to hotfix broken docs build 2021-02-14 21:05:32 -05:00
Roman Mogylatov
02dea7bce5 Merge branch 'release/4.22.0' into master 2021-02-14 19:10:06 -05:00
Roman Mogylatov
22bc447d14 Bump version to 4.22.0 2021-02-14 19:09:44 -05:00
Roman Mogylatov
8b770772a1 Add container name to the representation of the dependency provider 2021-02-14 19:09:08 -05:00
Roman Mogylatov
0d8f2ff44e Add cross-links between container singletons and reset container singletons docs pages 2021-02-14 18:51:55 -05:00
Roman Mogylatov
8eea9c4e45
Implement container.check_dependencies() (#396)
* Add implementation, typing stubs, and tests

* Add docs and example

* Update changelog
2021-02-14 18:47:15 -05:00
Roman Mogylatov
2c5bb45bf1 Merge remote-tracking branch 'origin/master' into develop 2021-02-14 18:30:26 -05:00
Roman Mogylatov
2127e3cef9 Merge branch 'release/4.21.0' into master 2021-02-13 09:18:12 -05:00
Roman Mogylatov
7fdd25e46f Bump version to 4.21.0 2021-02-13 09:17:59 -05:00
Roman Mogylatov
839a319831
Better error message for dependency provider (#395)
* Add prototype for flat resolving

* Add working prototype for sample 1 and 3

* Add working prototype, requires deep refactoring

* Update DependenciesContainer to handle Contrainer provider

* Fix Dependency provider copying issue

* Add hardening fix for Self provider to avoid copying bugs

* Fix flaky container copy issue

* Rename set_parent() to assign_parent()

* Refactor Dependency provider and its typing stub

* Add tests for Dependency provider

* Update makefile to run coverage when tests fail

* Clean up DependenciesContainer provider and add tests

* Clean up Container provider and add tests

* Clean up container instance and add tests

* Refactor isinstance() checks

* Clean up DeclarativeContainer and add tests

* Update docs and examples

* Update changelog

* Revoke makefile change
2021-02-13 09:16:38 -05:00
Roman Mogylatov
e65212e231 Revoke makefile change 2021-02-13 09:12:54 -05:00
Roman Mogylatov
2621e505cd Update changelog 2021-02-13 09:11:52 -05:00
Roman Mogylatov
50d05d43c6 Update docs and examples 2021-02-13 09:07:22 -05:00
Roman Mogylatov
21c0c82144 Clean up DeclarativeContainer and add tests 2021-02-13 08:36:45 -05:00
Roman Mogylatov
1d884b5101 Refactor isinstance() checks 2021-02-12 19:01:54 -05:00
Roman Mogylatov
3ba65da1ad Clean up container instance and add tests 2021-02-12 18:55:20 -05:00
Roman Mogylatov
cb7c13f1ba Clean up Container provider and add tests 2021-02-12 16:58:23 -05:00
Roman Mogylatov
351bdd282e Clean up DependenciesContainer provider and add tests 2021-02-12 09:16:21 -05:00
Roman Mogylatov
9677701626 Update makefile to run coverage when tests fail 2021-02-12 09:15:49 -05:00
Roman Mogylatov
b376836150 Add tests for Dependency provider 2021-02-12 08:35:04 -05:00
Roman Mogylatov
99e404650f Refactor Dependency provider and its typing stub 2021-02-12 08:02:44 -05:00
Roman Mogylatov
b68d4d8d08 Rename set_parent() to assign_parent() 2021-02-11 18:06:47 -05:00
Roman Mogylatov
dd6b0caffd Fix flaky container copy issue 2021-02-11 16:32:31 -05:00
Roman Mogylatov
980f9fc2bc Add hardening fix for Self provider to avoid copying bugs 2021-02-11 09:20:05 -05:00
Roman Mogylatov
e29040d2ee Fix Dependency provider copying issue 2021-02-11 09:09:52 -05:00
Roman Mogylatov
7ef3c63ca9 Update DependenciesContainer to handle Contrainer provider 2021-02-11 07:50:52 -05:00
Roman Mogylatov
5f34c7ce3f Add working prototype, requires deep refactoring 2021-02-10 08:52:13 -05:00
Roman Mogylatov
ff3ae95482 Add working prototype for sample 1 and 3 2021-02-10 07:57:04 -05:00
Roman Mogylatov
1c433ed0ad Add prototype for flat resolving 2021-02-09 08:57:31 -05:00
Roman Mogylatov
81da4e0451 Merge branch 'release/4.20.2' into master 2021-02-09 07:36:06 -05:00
Roman Mogylatov
5b18d609f1 Bump version to 4.20.2 2021-02-09 07:35:55 -05:00
Roman Mogylatov
47aa8c11fe Move Self provider docs to providers section 2021-02-09 07:34:46 -05:00
Roman Mogylatov
a9fd206aae Merge branch 'release/4.20.1' into master 2021-02-07 14:17:53 -05:00
Roman Mogylatov
719b61cf22 Bump version to 4.20.1 2021-02-07 14:17:40 -05:00
Roman Mogylatov
5e5531765d Merge branch 'release/4.20.0' into master 2021-02-07 14:14:35 -05:00
Roman Mogylatov
6b24cb84a5 Bump version to 4.20.0 2021-02-07 14:14:22 -05:00
Roman Mogylatov
674a6b0f9e
Container "self" injections (#392)
* Add implementation

* Add Self provider tests

* Add container tests

* Remove ellipsis from tests to make them pass on Python 2

* Add tests

* Add docs

* Improve traverse() typing stubs

* Update changelog
2021-02-07 14:13:23 -05:00
Roman Mogylatov
ce6d3df72c Merge branch 'release/4.19.0' into master 2021-02-05 18:28:44 -05:00
Roman Mogylatov
398d502981 Bump version to 4.19.0 2021-02-05 18:28:26 -05:00
Roman Mogylatov
19a2f551ae Update docs on creating custom providers with a requirement to specify `.related` property 2021-02-05 18:27:32 -05:00
Roman Mogylatov
2fe0e00cef
Singleton.full_reset() (#391)
* Improve .traverse() typing stubs

* Fix container.reset_singletons()

* Add implementation, tests, and typing stubs

* Add docs and example

* Update changelog
2021-02-05 18:17:44 -05:00
Roman Mogylatov
78f623c05b Merge branch 'release/4.18.0' into master 2021-02-05 17:24:00 -05:00
Roman Mogylatov
e80c56f9be Bump version to 4.18.0 2021-02-05 17:23:10 -05:00
Roman Mogylatov
b25356d2fa Fix tests 2021-02-05 17:21:26 -05:00
Roman Mogylatov
c964253204
Container.reset_singletons() (#390)
* Rename container tests

* Add implementation + tests

* Update changelog

* Add examples and docs
2021-02-05 17:14:10 -05:00
Roman Mogylatov
c4892af31e Refactor `container.apply_container_providers_overridings() to use container.traverse()` 2021-02-05 08:59:16 -05:00
Roman Mogylatov
c9ab7d540d Add tests for .provided & .call() 2021-02-05 08:48:25 -05:00
Roman Mogylatov
288284aa9c Make "make test" to be a default test command and run Python 3 tests 2021-02-05 08:36:36 -05:00
Roman Mogylatov
b3bd8e888b Add tests for selector provider 2021-02-05 08:34:20 -05:00
Roman Mogylatov
35f280ac8a Merge branch 'release/4.17.0' into master 2021-02-04 18:19:55 -05:00
Roman Mogylatov
2c1eb9f95f Bump version to 4.17.0 2021-02-04 18:19:40 -05:00
Roman Mogylatov
d45d98e300
Fastapi sqlalchemy example (#389)
* Add application

* Dockerize the app

* Fix 204 content-leength error

* Rename database file

* Add tests

* Add README

* Fix a typo in FastAPI example

* Add docs on FastAPI + SQLAlchemy example

* Update changelog

* Add link to the example to README and other docs pages

* Add EOF to the config.yml
2021-02-04 18:18:25 -05:00
Roman Mogylatov
a1f779a9f3 Merge branch 'release/4.16.0' into master 2021-02-03 15:40:53 -05:00
Roman Mogylatov
892330f43c Bump version to 4.16.0 2021-02-03 15:40:41 -05:00
Roman Mogylatov
cba5aefd65 Add container base class 2021-02-03 15:36:37 -05:00
Roman Mogylatov
6cc1a0c61f Merge branch 'release/4.15.0' into master 2021-02-03 09:22:58 -05:00
Roman Mogylatov
f48fd159f0 Bump version to 4.15.0 2021-02-03 09:22:40 -05:00
Roman Mogylatov
15fa6c301e
Pydantic settings support (#388)
* Add implementation and basic test

* Add full test coverage + bugfix

* Add test coverage for .from_yaml() method

* Update setup.py, tox and dev requirements

* Stop running pydantic tests on Python 3.5 and below

* Remove pydantic from tox Python < 3.6

* Add example and docs

* Update features block

* Add extra test

* Update changelog
2021-02-03 09:21:32 -05:00
Roman Mogylatov
1fabbf314b Merge branch 'release/4.14.0' into master 2021-02-01 09:57:43 -05:00
Roman Mogylatov
fbe51b95e8 Bump version to 4.14.0 2021-02-01 09:55:21 -05:00
Roman Mogylatov
e9a16d1f17 Fix #380: .init_resources() and .shutdown_resource() dont ignore nested resources 2021-02-01 09:54:36 -05:00
Roman Mogylatov
3ca6dd9af1
Providers traversal (#385)
* Implement providers traversal in first precision

* Implement traversal for all providers

* Update traverse interface + add some tests

* Refactor tests

* Add tests for callable provider

* Add configuration tests

* Add Factory tests

* Add FactoryAggrefate tests

* Add .provides attribute to singleton providers

* Add singleton provider tests

* Add list and dict provider tests

* Add resource tests

* Add Container provider tests

* Add Selector provider tests

* Add ProvidedInstance provider tests

* Add AttributeGetter provider tests

* Add ItemGetter provider tests

* Add MethodCaller provider tests

* Refactor container interface

* Update resource provider string representation

* Add .initializer attribute to Resource provider

* Add docs and examples

* Remove not needed EOL in the tests

* Make cosmetic refactoring

* Ignore flake8 line width error in traverse example
2021-02-01 09:42:21 -05:00
Roman Mogylatov
0c1a08174f Merge branch 'release/4.13.2' into master 2021-01-29 16:58:44 -05:00
Roman Mogylatov
cd949c6a0b Bump version to 4.13.2 2021-01-29 16:58:30 -05:00
Roman Mogylatov
4942f9c160 Fix PyCharm typing warning in container.wire() method 2021-01-29 16:58:08 -05:00
Roman Mogylatov
b7afbe2cdc Merge branch 'release/4.13.1' into master 2021-01-29 16:42:38 -05:00
Roman Mogylatov
fba00894ea Bump version to 4.13.1 2021-01-29 16:42:30 -05:00
Roman Mogylatov
39cb963351 367 Fix declarative container metaclass bug with child providers 2021-01-29 16:37:50 -05:00
Roman Mogylatov
f188811d87 Merge branch 'release/4.13.0' into master 2021-01-29 13:51:08 -05:00
Roman Mogylatov
a0ba7fd16c Bump version to 4.13.0 2021-01-29 13:50:53 -05:00
Roman Mogylatov
478ca18ae3
336 Dependency provider default (#382)
* Add implementation and tests

* Refactor dependency provider docs

* Update docs

* Update changelog
2021-01-29 13:49:40 -05:00
Roman Mogylatov
1f17bc6e08 Merge branch 'release/4.12.0' into master 2021-01-28 19:50:49 -05:00
Roman Mogylatov
ebeb258e96 Bump version to 4.12.0 2021-01-28 19:50:35 -05:00
Roman Mogylatov
eb587933f4
Implement wiring autoloader (#381)
* Implement wiring autoloader

* Add docs

* Update changelog
2021-01-28 19:49:24 -05:00
Roman Mogylatov
9225f9dcd6 Merge branch 'release/4.11.3' into master 2021-01-28 08:46:00 -05:00
Roman Mogylatov
aca67663b6 Bump version to 4.11.3 2021-01-28 08:44:10 -05:00
Roman Mogylatov
6224131a76 358 Replace configuration option weakref to root with regular ref 2021-01-28 08:40:43 -05:00
Roman Mogylatov
9136fdcbb5 Merge branch 'release/4.11.2' into master 2021-01-27 14:19:27 -05:00
Roman Mogylatov
725e3fa322 Bump version to 4.11.2 2021-01-27 14:03:08 -05:00
Roman Mogylatov
ba0fb38ad0 379 Fix a bug in `providers.Container` when it's declared not at class root level 2021-01-27 14:02:13 -05:00
Roman Mogylatov
874b13fdea Merge branch 'release/4.11.1' into master 2021-01-27 09:22:11 -05:00
Roman Mogylatov
92938b018d
Improve @containers.copy to replace subcontainer providers (#378)
* Improve @containers.copy to replace subcontainer providers

* Bump version to 4.11.1
2021-01-27 09:21:45 -05:00
Roman Mogylatov
78479c65e6 Merge branch 'release/4.11.0' into master 2021-01-27 07:50:18 -05:00
Roman Mogylatov
f5b2862354 Switch CD to prod 2021-01-27 07:49:53 -05:00
Roman Mogylatov
9efc8ed488 Test docs - ok 2021-01-27 07:45:48 -05:00
Roman Mogylatov
9bdce2d376 Test docs publishing 2021-01-27 07:41:25 -05:00
Roman Mogylatov
63dade0615 Bump version to 4.11.0 2021-01-27 07:39:38 -05:00
Roman Mogylatov
7b33733bdf Update badge 2021-01-27 07:38:35 -05:00
Roman Mogylatov
717f7a0497
Travis CI -> GitHub Actions (#377)
* Add tests config

* Try run tests on multiple versions

* Add jobs for Python 3.5, 3.6, 3.7

* Add Python 3.4

* Add Python 2.7 job

* Add PyPy and PyPy3 jobs

* Add tests coverage job

* Try to add manual trigger for tests

* Fix coveralls token passing

* Change coverage job name

* Update env sections

* Update run and env sections

* Add COVERALLS_GIT_BRANCH

* Try set branch name

* Set branch name and token

* Update tox.ini to pass env variables

* Update tox.ini

* Re-arrange run actions

* Refactor tests workflow

* Add linters workflow

* Move linters to tests workflow

* Move branch name

* Create common linters job

* Rename tests and linters workflow

* Add pull_request event for tests and linters jobs

* Add publishing workflow

* Try quote asteriks

* Update publishing workflow to publish to test server

* Change publishing workflow name

* Add linux x64 wheels publishing job

* Bump version

* Add publishing wheels on mac and windows

* Fix windows builds

* Refactor to two stages build

* Rename build wheels job

* Add experimental aarch64 builds

* Rename custom archs job

* Add tests & linters to publishing job

* Bump version

* Add docs publishing

* Rename aarch64 job

* Rename aarch64 job

* Revert version change

* Update coveralls job

* Experiment with coveralls

* Experiment with branch name

* Update tox.ini to pass github token

* Update tox.ini to pass all GH vars

* Remove coveralls branch

* Remove travis ci config
2021-01-26 21:11:27 -05:00
Roman Mogylatov
dfedead4f0 Add yaml tests skipping on Python 3.4 2021-01-25 17:32:22 -05:00
Roman Mogylatov
4cc39fc6eb
369 Add required argument to config from_* methods (#376)
* Update typing stubs

* Update from_yaml() method

* Update from_ini() method

* Update from_dict() method

* Update from_env() method

* Update documentation

* Update changelog

* Update changelog

* Make doc block fix

* Add extra test for from_ini()
2021-01-24 10:27:45 -05:00
Roman Mogylatov
2d49308c16
Configuration strict mode raise on non existing files (#375)
* Update from_yaml()

* Refactor YAML environment variables interpolation

* Update from_ini()

* Refactor UNDEFINED

* Update from_env()

* Update from_dict()

* Update docs

* Update changelog
2021-01-23 22:37:50 -05:00
Roman Mogylatov
500855895b
372 Change yaml loader to safe loader (#373)
* Add safe loader with env interpolation and an arg to provide custom loader

* Add docs

* Update changelog
2021-01-21 18:00:24 -05:00
Roman Mogylatov
582c232790 Update version to dev 2021-01-21 17:57:31 -05:00
Roman Mogylatov
d533ac110a Add extra tests for asynchronous injections 2021-01-21 11:42:22 -05:00
Roman Mogylatov
c16f974517 Refactor asynchronous injections 2021-01-21 11:20:24 -05:00
Roman Mogylatov
4b0272ab30 Fix #368 Async providers do not work with async dependencies 2021-01-21 10:58:49 -05:00
Roman Mogylatov
349c252b50 Merge branch 'release/4.10.3' into master 2021-01-20 09:04:24 -05:00
Roman Mogylatov
c865e7c90d Bump version to 4.10.3 2021-01-20 09:04:11 -05:00
Roman Mogylatov
e338309c10 Merge branch 'develop' of https://github.com/ets-labs/python-dependency-injector into develop 2021-01-20 08:59:49 -05:00
Roman Mogylatov
9f7dbe89f6 Merge branch 'release/4.10.2' into master 2021-01-20 08:58:32 -05:00
Roman Mogylatov
0cc63cd075 Merge branch 'release/4.10.2' into master 2021-01-19 17:51:00 -05:00
Roman Mogylatov
a635e46b59 Bump version to 4.10.2 2021-01-19 17:50:46 -05:00
Roman Mogylatov
21cc6ffc1b Fix bug #361: failure on async resource depends on other async resource 2021-01-19 17:47:25 -05:00
Roman Mogylatov
2cfc61aa37 Merge branch 'release/4.10.1' into master 2021-01-18 21:03:09 -05:00
Roman Mogylatov
50c5c81fd7 Bump version to 4.10.1 2021-01-18 21:02:56 -05:00
Roman Mogylatov
0ab0239d47 Switch Coveralls reporting Travis Job to run on Python 3.9. 2021-01-18 20:56:55 -05:00
Roman Mogylatov
4991c5d4b0 Fix a Python 3.9 GenericAlias introspection bug, issue #362 2021-01-18 20:49:56 -05:00
Roman Mogylatov
2ced67d52b Merge branch 'release/4.10.0' into master 2021-01-16 08:55:15 -05:00
Roman Mogylatov
7ada2dc938 Bump version to 4.10.0 2021-01-16 08:55:00 -05:00
Roman Mogylatov
d74e8248a1
Required config options and strict mode (#360)
* Add strict mode + tests

* Add .required() for configuration option

* Add wiring tests for required() modifier

* Add wiring support

* Add tests for defined None values in required/strict mode

* Add docs

* Update changelog

* Update example doc block
2021-01-16 08:53:40 -05:00
Roman Mogylatov
3b69ed91c6 Merge branch 'release/4.9.1' into master 2021-01-15 16:22:28 -05:00
Roman Mogylatov
21fb81dffb Bump version to 4.9.1 2021-01-15 16:22:12 -05:00
Roman Mogylatov
d9ff0a01fd Fix a bug in the `Configuration` provider to correctly handle undefined values 2021-01-15 16:21:57 -05:00
Roman Mogylatov
b873137614 Merge branch 'release/4.9.0' into master 2021-01-15 07:24:02 -05:00
Roman Mogylatov
07d6261e3f Bump version to 4.9.0 2021-01-15 07:23:45 -05:00
Roman Mogylatov
907a4f1887
Add dependencies attribute to declarative and dynamic containers (#359)
* Add .dependencies attribute to declarative and dynamic containers

* Update changelog

* Add typing tests
2021-01-15 07:20:37 -05:00
Roman Mogylatov
3e207a4f21 Merge branch 'release/4.8.3' into master 2021-01-15 06:44:54 -05:00
Roman Mogylatov
a996c142ac Bump version to 4.8.3 2021-01-15 06:44:41 -05:00
Roman Mogylatov
1c87a9973d Fix a bug in the `Configuration provider to correctly handle overriding by None`. 2021-01-15 06:44:24 -05:00
Roman Mogylatov
1cbd3a0215 Merge branch 'release/4.8.2' into master 2021-01-13 17:08:36 -05:00
Roman Mogylatov
21053b3fb1 Bump version to 4.8.2 2021-01-13 17:08:26 -05:00
Roman Mogylatov
1628cfaf28 Fix `Container` provider to apply context overridings on root container initialization 2021-01-13 17:07:41 -05:00
Roman Mogylatov
de6c3cda78 Fix side effect in `Container` provider overriding 2021-01-13 09:11:24 -05:00
Roman Mogylatov
d9f914dfeb Merge branch 'release/4.8.1' into master 2021-01-12 17:50:28 -05:00
Roman Mogylatov
b425ac955c Bump version to 4.8.1 2021-01-12 17:50:11 -05:00
Roman Mogylatov
dd57c68ce5 Fix declarative container multi-level inheritance issue 2021-01-12 17:49:48 -05:00
Roman Mogylatov
46422a6845 Merge branch 'release/4.8.0' into master 2021-01-12 08:42:38 -05:00
Roman Mogylatov
6b8239ebb4 Bump version to 4.8.0 2021-01-12 08:42:14 -05:00
Roman Mogylatov
cd4807b2f9 Add support of overriding for container provider 2021-01-12 08:41:59 -05:00
Roman Mogylatov
cebeb79b93 Merge branch 'release/4.7.0' into master 2021-01-11 08:19:59 -05:00
Roman Mogylatov
86c4a22b5f Bump version to 4.7.0 2021-01-11 08:19:34 -05:00
Roman Mogylatov
8dd8446d39
Wiring container injection (#353)
* Add container injections to wiring

* Add example

* Update docs

* Update changelog

* Improve typing
2021-01-11 08:18:02 -05:00
Roman Mogylatov
6e77a95909 Merge branch 'release/4.6.1' into master 2021-01-10 20:02:57 -05:00
Roman Mogylatov
ce1bf704f2 Bump version to 4.6.1 2021-01-10 20:02:46 -05:00
Roman Mogylatov
9cd201a493 Merge branch 'release/4.6.0' into master 2021-01-10 19:32:29 -05:00
Roman Mogylatov
dfb7bb5a93 Bump version to 4.6.0 2021-01-10 19:31:59 -05:00
Roman Mogylatov
48a2bcc039 Update copyright year 2021-01-10 19:31:01 -05:00
Roman Mogylatov
feed916f46
Async resources and injections (#352)
* Add support of async injections into wiring

* Add support of async functions and async generators for resources

* Update resource provider typing stub for stutdown

* Add resource base class for async resources

* Fix tests

* Add tests for async injections in wiring @inject

* Refactor provider tests

* Add tests for async resources

* Rework async resources callbacks to .add_done_callback() style (fixes pypy3 issue)

* Add awaits into async resource class test

* Refactor FastAPI tests

* Implement async resources initialization in container

* Move container async resource tests to a separate module for Python 3.6+

* Fix init async resources in container on Python 2

* Add first dirty async injections implementation

* Fix isawaitable error

* Turm asyncio import to conditional for safer Py2 usage

* Refactor kwargs injections

* Implement positional injections, add tests and make refactoring

* Implement attribute injections and add tests

* Add singleton implementation + tests for all singleton types

* Implement injections in thread-local and thread-safe singleton providers

* Update .provided + fix resource concurent initialization issue

* Implement async mode for Dependency provider

* Add async mode for the provider

* Add overload for Factory typing

* Add typing stubs for async resource

* Refactor abstract* providers __call__()

* Add async mode API + tests

* Add typing stubs & tests for async mode API

* Add tests for async mode auto configuration

* Refactor Provider.__call__() to use async mode api

* Refactor Dependency provider to use async mode api

* Add tests for Dependency provider async mode

* Add support of async mode for FactoryAggregate provider + tests

* Refactor Singleton provider to use async mode api

* Refactor ThreadSafeSingleton provider to use async mode api

* Refactor ThreadLocalSingleton provider to use async mode api

* Finish Singleton refactoring to use async mode api

* Refactor Resource provider to use async mode api

* Add Provider.async_() method + tests

* Add typing stubs for async_() method + tests

* Refactor Singleton typing stubs to return singleton from argument methods

* Refactor provider typing stubs

* Improve resource typing stub

* Add tests for async context kwargs injections

* Fix typo in resource provider tests

* Cover shutdown of not initialized resource

* Add test to cover resource initialization with an error

* Fix Singleton and ThreadLocalSingleton to handle initialization errors

* Add FastAPI + Redis example

* Make cosmetic fixes to FastAPI + Redis example

* Add missing development requirements

* Update module docblock in fastapi + redis example

* Add FastAPI + Redis example docs

* Add references to FastAPI + Redis example

* Refactor resource docs

* Add asynchronous resources docs

* Refactor wiring docs

* Add async injections docs for wiring

* Add async injections page and update docs index, readme, and key features pages

* Add providers async injections example

* Add docs on provider async mode enabling

* Reword async provider docs

* Add provider async mode docs

* Add cross links to async docs

* Mute flake8 errors in async provider examples

* Update changelog

* Make cosmetic fix to containers.pyx
2021-01-10 19:26:15 -05:00
Roman Mogylatov
9f6d2bb522 Update changelog and list of contributors 2020-12-30 13:26:28 -05:00
Fotis Koutoupas
aad84476d0
Fix flask ext warning message (#345) 2020-12-30 13:19:42 -05:00
Roman Mogylatov
89aeca76c0
Arm builds (#343)
* Add arm64 wheels travis build job

* Update changelog
2020-12-23 20:03:00 -05:00
Roman Mogylatov
47278030ce Merge branch 'release/4.5.4' into master 2020-12-10 18:28:37 -05:00
Roman Mogylatov
468451d4c0 Bump version to 4.5.4 2020-12-10 18:28:29 -05:00
Roman Mogylatov
10becb316f Hotfix travis issue with not working uploading of manylinux wheels 2020-12-10 18:26:05 -05:00
Roman Mogylatov
1c00243c09 Restore regular travis config 2020-12-10 18:24:28 -05:00
Roman Mogylatov
d51a7565e4 Test twine dependency resolution 2020-12-10 18:12:08 -05:00
Roman Mogylatov
ca1404694a Test twine uploads for linux builds 2020-12-10 17:52:11 -05:00
Roman Mogylatov
873b0907ec Merge branch 'release/4.5.3' into master 2020-12-05 22:14:44 -05:00
Roman Mogylatov
730baf87d8 Bump version to 4.5.3 2020-12-05 22:14:35 -05:00
Roman Mogylatov
c1e53e5edd Replace AsyncMock with simple mock class in FastAPI wiring tests for better compatibility 2020-12-05 22:08:05 -05:00
Roman Mogylatov
0b7cf3254e Fix test dependencies 2020-12-05 21:49:54 -05:00
Roman Mogylatov
b49f158583 Fix bug #331 2020-12-05 21:40:51 -05:00
Roman Mogylatov
ec49d56751 Add tests for FastAPI wiring 2020-12-05 21:36:30 -05:00
Roman Mogylatov
c4dd923f37 Merge branch 'release/4.5.2' into master 2020-12-04 20:19:12 -05:00
Roman Mogylatov
de092023b8 Bump version to 4.5.2 2020-12-04 20:18:39 -05:00
Roman Mogylatov
afa39b148e Fix issue 330: FastAPI Depends directive does not work after patching with @inject 2020-12-04 20:11:21 -05:00
Roman Mogylatov
5c4c84b34e Merge branch 'release/4.5.1' into master 2020-11-20 18:16:39 -05:00
Roman Mogylatov
4ff1a6eb25 Bump version to 4.5.1 2020-11-20 18:16:29 -05:00
Roman Mogylatov
9f314fd7e9 Merge branch 'release/4.5.0' into master 2020-11-20 18:10:13 -05:00
Roman Mogylatov
57faa5f93f Bump version to 4.5.0 2020-11-20 18:10:04 -05:00
Roman Mogylatov
cd2c5697c3 Add commands and handlers example 2020-11-20 18:09:34 -05:00
Roman Mogylatov
fbaf35244c Add example and docs 2020-11-20 17:57:33 -05:00
Roman Mogylatov
034e4814da Add support of non-string keys for Dict provider 2020-11-20 17:30:42 -05:00
Roman Mogylatov
c8178cecda Add extra typing test for provided instance of `DependenciesContainer` provider 2020-11-20 12:25:35 -05:00
Roman Mogylatov
8092421727 Add simple FastAPI example 2020-11-18 11:13:31 -05:00
Roman Mogylatov
ee965f9782 Merge branch 'release/4.4.1' into master 2020-11-17 23:59:44 -05:00
Roman Mogylatov
d581a28b6e Bump version to 4.4.1 2020-11-17 23:59:33 -05:00
Roman Mogylatov
49921dcf9d Remove a typo from the Flask tutorial 2020-11-17 23:50:56 -05:00
Roman Mogylatov
950d5a5e6e Update FastAPI example 2020-11-17 23:46:30 -05:00
Roman Mogylatov
d37ae8e7db Improve FastAPI integration 2020-11-17 23:44:32 -05:00
Roman Mogylatov
262c035bc1 Merge branch 'release/4.4.0' into master 2020-11-15 18:20:48 -05:00
Roman Mogylatov
a2b09c57dc Bump version to 4.4.0 2020-11-15 18:19:34 -05:00
Roman Mogylatov
092be74145 Add docs page on flask blueprints example 2020-11-15 18:09:45 -05:00
Roman Mogylatov
ca671abea6 Add flask blueprints example 2020-11-15 18:07:39 -05:00
Roman Mogylatov
ae3024588c
Wiring reengineering (#324)
* Bump version to 4.3.9: FastAPI example

* Reengineer wiring

* Add @inject decorator

* Add .workspace dir to gitignore

* Add generic typing for @inject

* Add type cast for @inject

* Update movie lister example

* Update cli application tutorial

* Update demo example

* Update wiring docs and examples

* Update aiohttp example and tutorial

* Update multiple containers example

* Update single container example

* Update decoupled packages example

* Update django example

* Update asyncio daemon example and tutorial

* Update FastAPI example

* Update flask example and tutorial

* Update sanic example

* Add wiring registry

* Add new line to .gitignore

* Add @inject to the test samples

* Fix flake8 errors
2020-11-15 16:06:42 -05:00
Roman Mogylatov
b0b8820ac1 Merge branch 'release/4.3.9' into master 2020-11-12 21:29:37 -05:00
Roman Mogylatov
9bcf875ef0 Bump version to 4.3.9: FastAPI example 2020-11-12 21:29:22 -05:00
Roman Mogylatov
bece33fc21 Fix fastapi example flake8 error 2020-11-12 17:56:47 -05:00
Roman Mogylatov
59f25241cc Add FastAPI mini app 2020-11-12 17:48:07 -05:00
Roman Mogylatov
af742b980a Merge branch 'release/4.3.8' into master 2020-11-12 16:32:31 -05:00
Roman Mogylatov
cdce5247c8 Bump version to 4.3.8 2020-11-12 16:31:20 -05:00
Roman Mogylatov
97c33442e0 Add wiring hotfix for fastapi 2020-11-12 15:54:49 -05:00
Roman Mogylatov
26a89d664b Merge branch 'release/4.3.7' into master 2020-11-10 17:02:56 -05:00
Roman Mogylatov
ccf6ccad54 Bump version to 4.3.7 2020-11-10 17:02:42 -05:00
Roman Mogylatov
985be71a04 Regenerate C sources after PR#322 2020-11-10 17:02:21 -05:00
Roman Mogylatov
bbaed9c061 Add Dmitry Rassoshenko to the list of contributors 2020-11-10 17:01:14 -05:00
Dmitry Rassoshenko
fb0d99c1c9
Fix race in ThreadSafeSingleton (#322) 2020-11-10 14:57:10 -05:00
Roman Mogylatov
4120afd1c3 Merge branch 'release/4.3.6' into master 2020-11-05 12:37:37 -05:00
Roman Mogylatov
3ff5c8ce82 Bump version to 4.3.6 2020-11-05 12:37:25 -05:00
Roman Mogylatov
02acaba034 Merge branch 'release/4.3.5' into master 2020-11-05 12:27:48 -05:00
Roman Mogylatov
6b93c2e412 Bump version to 4.3.5 2020-11-05 12:23:47 -05:00
Roman Mogylatov
3c71ba4b2a Fix wiring multiple imports, issue #320 2020-11-05 12:20:09 -05:00
Roman Mogylatov
4579e35d33 Merge branch 'release/4.3.4' into master 2020-11-05 10:20:39 -05:00
Roman Mogylatov
f3ec74a31f Bump version to 4.3.4 2020-11-05 10:20:23 -05:00
Roman Mogylatov
18ef566aae Fix issue #319 resulting in configuration.reset_override() not working properly 2020-11-05 10:16:39 -05:00
Roman Mogylatov
e847c357a6 Merge branch 'release/4.3.3' into master 2020-11-03 16:06:52 -05:00
Roman Mogylatov
25549d7cfe Bump version to 4.3.3 2020-11-03 16:06:42 -05:00
Roman Mogylatov
fb2d927cae Fix wiring for @classmethod and @staticmethod 2020-11-03 15:59:02 -05:00
Roman Mogylatov
c1cf1bfa1c Merge branch 'release/4.3.2' into master 2020-10-30 17:06:19 -04:00
Roman Mogylatov
b0d3f08aa6 Bump version to 4.3.2 2020-10-30 16:56:13 -04:00
Roman Mogylatov
e4e77d0cdb Fix wiring decorator 2020-10-30 16:55:37 -04:00
Roman Mogylatov
63977a73b2 Refactor wiring to reduce complexity 2020-10-30 16:47:26 -04:00
Roman Mogylatov
c5f799a1ec Fix issue with wiring and resource initialization 2020-10-30 16:40:27 -04:00
Roman Mogylatov
4c46d34b20 Merge branch 'release/4.3.1' into master 2020-10-29 23:00:53 -04:00
Roman Mogylatov
f65f8b1af9 Bump version to 4.3.1 2020-10-29 23:00:43 -04:00
Roman Mogylatov
84b0029494 Merge branch 'release/4.3.0' into master 2020-10-29 22:57:23 -04:00
Roman Mogylatov
d65b31865b Bump version to 4.3.0 2020-10-29 22:57:14 -04:00
Roman Mogylatov
707446a70f
Closing wiring marker (#315)
* Add closing marker

* Add example

* Fix flake8 errors

* Add test

* Update docs and README
2020-10-29 22:55:09 -04:00
Roman Mogylatov
b18385a867 Merge branch 'release/4.2.0' into master 2020-10-29 15:48:22 -04:00
Roman Mogylatov
21f0658ef3 Bump version to 4.2.0 2020-10-29 15:48:04 -04:00
Roman Mogylatov
30bc505b79 Update README and docs index 2020-10-29 15:46:43 -04:00
Roman Mogylatov
c3a04cc340 Add Python 3.9 classifier 2020-10-29 15:44:14 -04:00
Roman Mogylatov
eadea64e0f Add travis job for Python 3.9 2020-10-29 14:23:07 -04:00
Roman Mogylatov
e615b9c48c Merge branch 'release/4.1.8' into master 2020-10-28 22:31:08 -04:00
Roman Mogylatov
e3ccb0e764 Bump version to 4.1.8 2020-10-28 22:30:52 -04:00
Roman Mogylatov
018102b4e2 Update asyncio daemon to use Resource provider 2020-10-28 22:28:49 -04:00
Roman Mogylatov
d3ec1ef532 Update application examples to use Resource provider 2020-10-28 22:20:49 -04:00
Roman Mogylatov
fea8c33cd4 Merge branch 'release/4.1.7' into master 2020-10-28 21:02:31 -04:00
Roman Mogylatov
f7499354ec Bump version to 4.1.7 2020-10-28 21:02:21 -04:00
Roman Mogylatov
cdc5e84e7f Remove alabaster pinning 2020-10-28 20:48:21 -04:00
Roman Mogylatov
bf82f594b4 Add google analytics id 2020-10-28 20:48:07 -04:00
Roman Mogylatov
b7e7d8a171 Make alabaster theme pinning like on RTD 2020-10-28 20:36:45 -04:00
Roman Mogylatov
e4ed0bab6f Add building and pushing docs to s3 2020-10-28 17:37:43 -04:00
Roman Mogylatov
c0e5eac016 Merge branch 'release/4.1.6' into master 2020-10-28 14:23:14 -04:00
Roman Mogylatov
5c09be46d2 Bump version to 4.1.6 2020-10-28 14:23:00 -04:00
Roman Mogylatov
871bd617d4 Fix wiring linter errors 2020-10-28 13:50:51 -04:00
Roman Mogylatov
776cb4eebf Fix multiple containers wiring issue 2020-10-28 13:44:11 -04:00
Roman Mogylatov
2565a1eab0 Fix wiring for @classmethod 2020-10-28 13:11:07 -04:00
Roman Mogylatov
467e7ec9aa Merge branch 'release/4.1.5' into master 2020-10-27 17:48:14 -04:00
Roman Mogylatov
c7d8645044 Bump version to 4.1.5 2020-10-27 17:48:05 -04:00
Roman Mogylatov
9d5ccfea85 Debug TCI #5 2020-10-27 17:32:29 -04:00
Roman Mogylatov
532e1e3033 Debug TCI #4 2020-10-27 17:19:32 -04:00
Roman Mogylatov
b0501ca92a Debug TCI #3 2020-10-27 17:18:38 -04:00
Roman Mogylatov
3e4abb78e7 Debug Travis windows build #2 2020-10-27 17:16:23 -04:00
Roman Mogylatov
3cd590fc70 Debug Travis windows build #1 2020-10-27 17:00:29 -04:00
Roman Mogylatov
a66256a629 Merge branch 'release/4.1.4' into master 2020-10-27 14:36:22 -04:00
Roman Mogylatov
279910410e Bump version to 4.1.4 2020-10-27 14:36:11 -04:00
Roman Mogylatov
84888224a9 Fix .travis.yml 2020-10-27 14:29:28 -04:00
Roman Mogylatov
8381caec1e Test travic-ci.com 2020-10-27 14:24:23 -04:00
Roman Mogylatov
dfd0575e16 Revert "Add nl to readme"
This reverts commit 0938ccd46d.
2020-10-27 14:17:53 -04:00
Roman Mogylatov
27cebeb2c7 Revert "Remove nl from readme"
This reverts commit df3300588f.
2020-10-27 14:17:51 -04:00
Roman Mogylatov
df3300588f Remove nl from readme 2020-10-27 14:13:49 -04:00
Roman Mogylatov
0938ccd46d Add nl to readme 2020-10-27 14:13:37 -04:00
Roman Mogylatov
dd6de523cf Merge branch 'release/4.1.3' into master 2020-10-27 14:05:24 -04:00
Roman Mogylatov
969849e4da Bump version to 4.1.3 2020-10-27 14:05:16 -04:00
Roman Mogylatov
3b4fae8dca Add installation of certifi for windows ci builds 2020-10-27 14:04:52 -04:00
Roman Mogylatov
25d626e92f Migrate from travis-ci.org to travis-ci.com 2020-10-27 14:02:50 -04:00
Roman Mogylatov
ec0f9636bf Merge branch 'release/4.1.2' into master 2020-10-27 13:28:14 -04:00
Roman Mogylatov
c6e7551e87 Bump version to 4.1.2 2020-10-27 13:28:02 -04:00
Roman Mogylatov
cabeb6da55 Merge branch 'release/4.1.1' into master 2020-10-26 13:39:30 -04:00
Roman Mogylatov
b01ee7709c Bump version to 4.1.1 2020-10-26 13:39:13 -04:00
Roman Mogylatov
90af46da98 Merge branch 'release/4.1.0' into master 2020-10-24 20:58:22 -04:00
Roman Mogylatov
a3c7296879 Bump version to 4.1.0 2020-10-24 20:57:48 -04:00
Roman Mogylatov
47c79b2772
Resources (#312)
* Add prototype

* Add example

* Remove typing erros in Python 2.7 and 3.4

* Move resources example

* Draft resources docs

* Update resources docs

* Fix repr

* Rename dict provider test

* Add more tests

* Add tests + refactoring

* Add more tests

* Update tests to run only on 3.5+

* Update setup.py

* Add typing tests

* Update changelog

* Fix generator iteration

* Remove contextlib

* Hotfix aiohttp issue

* Move aiohttp fix to tox.ini

* Move aiohttp fix to a different place in tox
2020-10-24 20:56:32 -04:00
Roman Mogylatov
b54bcb7b31
Dict provider (#311)
* Add tests

* Add implementation and typing stubs

* Update README and docs pages

* Add example and docs

* Update changelog

* Add long description to the doc block
2020-10-22 14:49:39 -04:00
Roman Mogylatov
5c1486e1a3
Un deprecate container decorators (#310)
* Remove deprecation warnings

* Add example and docs

* Update changelog
2020-10-22 12:00:46 -04:00
Roman Mogylatov
97731db180 Update license year 2020-10-21 17:06:12 -04:00
Roman Mogylatov
081fccea93 Add favicon 2020-10-21 17:01:31 -04:00
Roman Mogylatov
c81194682b Remove redirect in bages 2020-10-21 16:55:28 -04:00
Roman Mogylatov
3a9e64af8f Merge branch 'release/4.0.6' into master 2020-10-20 17:50:47 -04:00
Roman Mogylatov
c90f6c1b97 Bump version to 4.0.6 2020-10-20 17:50:31 -04:00
Roman Mogylatov
4ddac663d9
Fix wiring for package init (#308)
* Add test

* Add fix

* Add extra test

* Remove package imports on discovery for Python versions < 3.6

* Move wiring samples to a different directory
2020-10-20 17:48:54 -04:00
Roman Mogylatov
fa81cadf29 Merge branch 'release/4.0.5' into master 2020-10-19 17:35:26 -04:00
Roman Mogylatov
ca54db6d05 Bump version to 4.0.5 2020-10-19 17:35:12 -04:00
Roman Mogylatov
ff4d24706e
Move "provided" attribute (#306)
* Update typing stub

* Move attribute

* Add typing test

* Update docs

* Add test

* Update changelog
2020-10-19 17:21:38 -04:00
Roman Mogylatov
452a13c9f7
Update all links to docs to use https (#305)
* Update README

* Update docs

* Update examples

* Update changelog
2020-10-19 17:18:39 -04:00
Roman Mogylatov
ca9a2a5692 Merge branch 'release/4.0.4' into master 2020-10-18 22:28:08 -04:00
Roman Mogylatov
81c67f8b27 Bump version to 4.0.4 2020-10-18 22:27:53 -04:00
Roman Mogylatov
0ffa1e8392 Fix typing stub for container.override() method 2020-10-18 22:22:11 -04:00
Roman Mogylatov
4e5083693d Merge branch 'release/4.0.3' into master 2020-10-16 21:44:27 -04:00
Roman Mogylatov
44e0a03148 Bump version to 4.0.3 2020-10-16 21:44:12 -04:00
Roman Mogylatov
f1867b6bf4
Deprecate declarative container decorators (#303) 2020-10-16 21:43:21 -04:00
Roman Mogylatov
11ac677d42 Merge branch 'release/4.0.2' into master 2020-10-16 16:38:56 -04:00
Roman Mogylatov
619fa1f25c Bump version to 4.0.2 2020-10-16 16:38:37 -04:00
Roman Mogylatov
56c9023b2d
Fix override and copy decorator stubs (#302)
* Fix stubs and add tests

* Fix tests

* Fix stubs
2020-10-16 16:36:07 -04:00
Roman Mogylatov
88b3482ced Merge branch 'release/4.0.1' into master 2020-10-16 14:10:37 -04:00
Roman Mogylatov
09d1c4ce9f Bump versionto 4.0.1 2020-10-16 14:10:14 -04:00
Rüdiger Busche
819023e7aa
Make Configuration.from_ methods accept Path (#300)
Co-authored-by: rbusche <rbusche@inserve.de>
2020-10-16 13:57:28 -04:00
Roman Mogylatov
39f3f3a623 Merge branch 'release/4.0.0' into master 2020-10-09 16:22:40 -04:00
Roman Mogylatov
a6838dcb74 Fix README 2020-10-09 16:18:55 -04:00
Roman Mogylatov
f97c486811 Merge branch 'release/4.0.0' into master 2020-10-09 15:17:39 -04:00
Roman Mogylatov
846deaa4dc Bump version to 4.0.0 2020-10-09 15:17:23 -04:00
Roman Mogylatov
07d4f7e74f
Develop 4.0 (#298)
* Add wiring (#294)

* Add wiring module

* Fix code style

* Fix package test

* Add version fix

* Try spike for 3.6

* Try another fix with metaclass

* Downsample required version to 3.6

* Introduce concept with annotations

* Fix bugs

* Add debug message

* Add extra tests

* Add extra debugging

* Update config resolving

* Remove 3.6 generic meta fix

* Fix Flake8

* Add spike for 3.6

* Add Python 3.6 spike

* Add unwire functionality

* Add support of corouting functions

* Bump version to 4.0

* Updaet demo example

* Add pydocstyle ignore for demo

* Add flake8 ignore for demo

* Update aiohttp example

* Update flask example

* Rename aiohttp example directory

* Rename views module to handlers in aiohttp example

* Add sanic example

* Remove not needed images

* Update demo

* Implement wiring for Provide[foo.provider]

* Implement Provide[foo.provided.bar.baz.call()]

* Make flake8 happy

* Wiring refactoring (#296)

* Refactor wiring

* Add todos to wiring

* Implement wiring of config invariant

* Implement sub containers wiring + add tests

* Add test for wiring config invariant

* Add container.unwire() typing stub

* Deprecate ext package modules and remove types module

* Deprecate provider.delegate() method

* Add __all__ for wiring module

* Add protection for wiring only declarative container instances

* Bump version to 4.0.0a2

* Add wiring docs

* Add wiring of class methods

* Remove unused import

* Add a note on individuals import to wiring docs

* Add minor improvement to wiring doc

* Update DI in Python page

* Update key features

* Update README concep and FAQ

* Add files via upload

* Update README.rst

* Update README.rst

* Update README.rst

* Update docs index page

* Update README

* Remove API docs for flask and aiohttp ext

* Add wiring API docs

* Update docs index

* Update README

* Update readme and docs index

* Change wording in README

* Django example (#297)

* Add rough django example

* Remove sqlite db

* Add gitignore

* Fix flake8 and pydocstyle errors

* Add tests

* Refactor settings

* Move web app to to the root of the project

* Add bootstrap 4

* Add doc blocks for web app

* Add coverage

* Fix typo in flask

* Remove not needed newlines

* Add screenshot

* Update django app naming

* Add django example to the docs

* Update changelog

* Update Aiohttp example

* Add sanic example to the docs

* Make a little fix in django example docs page

* Add flask example to the docs

* Add aiohttp example to the docs

* Update installation docs page

* Fix .delegate() deprecation

* Refactor movie lister to use wiring

* Make micro cosmetic changes to flask, aiohttp & sanic examples

* Refactor single container example to use wiring

* Refactor multiple container example to use wiring

* Add return type to main() in application examples

* Refactor decoupled packages example to use wiring

* Refactor code layout for DI demo example

* Update wiring feature message

* Add more links to the examples

* Change code layout in miniapps

* Update sanic example

* Update miniapp READMEs

* Update wiring docs

* Refactor part of cli tutorial

* Refactor CLI app tutorial

* Update test coverage results in movie lister example and tutorial

* Make some minor updates to aiohttp and cli tutorials

* Refactor flask tutorial

* Make cosmetic fix in flask example

* Refactor Flask tutorial: Connect to the GitHub

* Refactor Flask tutorial: Search service

* Refactor Flask tutorial: Inject search service into view

* Refactor Flask tutorial: Make some refactoring

* Finish flask tutorial refactoring

* Update tutorials

* Refactor  asyncio monitoring daemon example application

* Fix tutorial links

* Rename asyncio miniapp

* Rename tutorial image dirs

* Rename api docs tol-level page

* Refactor initial sections of asyncio daemon tutorial

* Refactor asyncio tutorial till Example.com monitor section

* Refactor asyncio tutorial example.com monitor section

* Refactor asyncio tutorial httpbin.org monitor tutorial

* Refactor tests section of asyncio daemon tutorial

* Update conclusion of asyncio daemon tutorial

* Rename tutorial images

* Make cosmetic update to flask tutorial

* Refactor aiohttp tutorial: Minimal application section

* Refactor aiohttp tutorial: Giphy API client secion

* Refactor aiohttp tutorial secion: Make the search work

* Refactor aiohttp tutorial tests section

* Refactor aiohttp tutorial conclusion

* Upgrade  Cython to 0.29.21

* Update changelog

* Update demo example

* Update wording on index pages

* Update changelog

* Update code layout for main demo
2020-10-09 15:16:27 -04:00
Roman Mogylatov
53b7ad0275 Merge branch 'release/3.44.0' into master 2020-09-13 20:56:13 -04:00
Roman Mogylatov
1f136e427d Bump version to 3.44.0 2020-09-13 20:51:10 -04:00
Roman Mogylatov
9ee4959f76 Update README 2020-09-13 20:48:25 -04:00
Roman Mogylatov
39368591b9 Move generic types test to separate module 2020-09-13 20:38:23 -04:00
Roman Mogylatov
d8439a28b1
Make provider generic type (#293)
* Add __class_getitem__ for Provider to null the typing in runtime

* Make Provider stub generic and remove types module

* Update types module tests

* Return types module with deprecation warning

* Return types module with deprecation warning

* Update changelog

* Add docs page
2020-09-13 20:32:21 -04:00
Roman Mogylatov
f56b5398ef Merge branch 'release/3.43.1' into master 2020-09-09 23:48:30 -04:00
Roman Mogylatov
6febd03646 Bump version to 3.43.1 2020-09-09 23:48:08 -04:00
Roman Mogylatov
0cddc4cf25 Merge branch 'release/3.43.0' into master 2020-09-09 23:36:33 -04:00
Roman Mogylatov
07f050d2ad Bump version to 3.43.0 2020-09-09 23:36:13 -04:00
Roman Mogylatov
203427aa97 Fix few typos 2020-09-09 23:34:59 -04:00
Roman Mogylatov
ffc477d1ee Update API docs 2020-09-09 22:23:28 -04:00
Roman Mogylatov
505ccf5a1d Fix a few typos 2020-09-09 22:23:14 -04:00
Roman Mogylatov
5740dd6df5 Remove not relevant "speech" example 2020-09-09 21:34:30 -04:00
Roman Mogylatov
ac8212a95b Merge branch 'release/3.42.0' into master 2020-09-09 18:02:53 -04:00
Roman Mogylatov
a305660a08 Bump version to 3.42.0 2020-09-09 18:02:37 -04:00
Roman Mogylatov
21764dbeec Fix sphinx warning 2020-09-09 17:59:44 -04:00
Roman Mogylatov
172c175e89 Fix some wording 2020-09-09 17:58:28 -04:00
Roman Mogylatov
8dcf6d99ce Update README 2020-09-09 17:56:48 -04:00
Roman Mogylatov
5cb7917a68 Update changelog 2020-09-09 17:53:19 -04:00
Roman Mogylatov
b4772af2c1 Update README 2020-09-09 17:53:00 -04:00
Roman Mogylatov
7e11d56ad6 Delete "What is DI?" documentation page 2020-09-09 17:52:45 -04:00
Roman Mogylatov
81ab8f807a Update DI in Python docs page 2020-09-09 17:39:49 -04:00
Roman Mogylatov
2b4d211207 Add ref marker to key features page 2020-09-08 21:57:37 -04:00
Roman Mogylatov
f75d90b21b Change wording in the "What is DI?" page 2020-09-08 21:27:57 -04:00
Roman Mogylatov
31f15c0a13 Merge branch 'release/3.41.0' into master 2020-09-07 22:07:22 -04:00
Roman Mogylatov
ba574660d8 Bump version to 3.41.0 2020-09-07 22:07:09 -04:00
Roman Mogylatov
2d28bc0d02 Add a link to the decoupled packages example to the introduction 2020-09-07 22:06:59 -04:00
Roman Mogylatov
039e51d4ba Delete mail service example mini app 2020-09-07 22:04:50 -04:00
Roman Mogylatov
139e67dd95 Delete api client example mini app 2020-09-07 22:02:33 -04:00
Roman Mogylatov
e1844a3040 Refactor factory of factories pattern example 2020-09-07 21:57:43 -04:00
Roman Mogylatov
8284d1f169 Refactor chained factories pattern example 2020-09-07 21:45:03 -04:00
Roman Mogylatov
d93c4a419b Update changelog 2020-09-07 12:34:49 -04:00
Roman Mogylatov
36ece67586 Add docs for the use cases example 2020-09-07 12:31:59 -04:00
Roman Mogylatov
f84d3e6f4e Refactor main module of the decoupled packages example 2020-09-07 12:05:12 -04:00
Roman Mogylatov
af51937004 Refactor main module 2020-09-07 12:03:49 -04:00
Roman Mogylatov
098ecb4eec Fix declarative container mypy stub 2020-09-07 11:53:03 -04:00
Roman Mogylatov
5306b27c48 Refactor password hashing example 2020-09-07 11:51:17 -04:00
Roman Mogylatov
e257fd9cb0 Merge branch 'release/3.40.0' into master 2020-09-06 21:55:17 -04:00
Roman Mogylatov
6d2a0382a7 Bump version to 3.40.0 2020-09-06 21:54:58 -04:00
Roman Mogylatov
29f209d382
Update bundles example (#292)
* Fix dependency provider stub issue with required init arg

* Refactor bundles example app

* Rename bundles package

* Rename bundles example container

* Rename bundles mini app to decoupled packages

* Move decoupled packages example to main examples

* Fix a typo

* Add meta
2020-09-06 21:51:38 -04:00
Roman Mogylatov
06bc0f1bac Merge branch 'release/3.39.0' into master 2020-09-04 23:23:16 -04:00
Roman Mogylatov
5bb9d221a5 Bump version to 3.39.0 2020-09-04 23:22:58 -04:00
Roman Mogylatov
bf978601ba
Refactor services miniapps (#291)
* Refactor services mini app with single container

* Make few little fixes to single container app

* Update requirements.txt for single container example

* Refactor multiple containers example

* Add single container docs page

* Create multiple containers page
2020-09-04 23:19:32 -04:00
Roman Mogylatov
d16e8817db Merge branch 'release/3.38.1' into master 2020-09-03 23:25:47 -04:00
Roman Mogylatov
72b2d0570f Bump version to 3.38.1 2020-09-03 23:25:32 -04:00
Roman Mogylatov
4ec3cce1d0 Merge branch 'release/3.38.0' into master 2020-09-03 23:22:32 -04:00
Roman Mogylatov
d6dbef0a75 Bump version to 3.38.0 2020-09-03 23:22:11 -04:00
Roman Mogylatov
0a10f32233 Remove old di demo 2020-09-03 23:21:09 -04:00
Roman Mogylatov
f0004c805f Fix typo 2020-09-03 23:13:17 -04:00
Roman Mogylatov
74df2ed00d Fix typo 2020-09-03 23:11:43 -04:00
Roman Mogylatov
14c2ecae8f Update "What is What is dependency injection?" documentation page 2020-09-03 23:09:21 -04:00
Roman Mogylatov
2cf5efa031 Merge branch 'release/3.37.0' into master 2020-09-03 18:06:01 -04:00
Roman Mogylatov
5f7d978012 Bump version to 3.37.0 2020-09-03 18:05:45 -04:00
Roman Mogylatov
b5b6c1f680 Fix flake8 warning in factory provided type example 2020-09-03 18:05:28 -04:00
Roman Mogylatov
913ce01475 Update key features 2020-09-03 18:03:21 -04:00
Roman Mogylatov
441cc66427 Improve singleton provider docs 2020-09-03 17:57:26 -04:00
Roman Mogylatov
ad260fe709 Add container usage to the custom provider example 2020-09-03 17:56:54 -04:00
Roman Mogylatov
d6e4e8fb08 Add container usage to provided instance examples 2020-09-03 17:48:45 -04:00
Roman Mogylatov
4f111aae9b Update provider overriding example to use container and fix bug 2020-09-03 17:42:15 -04:00
Roman Mogylatov
d61281a0b9 Add usage of the container to the selector example 2020-09-03 17:38:52 -04:00
Roman Mogylatov
e48746d65f Add usage of the container to the configuration examples 2020-09-03 17:37:03 -04:00
Roman Mogylatov
2a23f3d2f4 Add container usage for list provider example 2020-09-03 17:03:28 -04:00
Roman Mogylatov
6528411271 Add container usage for object provider example 2020-09-03 17:00:14 -04:00
Roman Mogylatov
b074d2aeb7 Add container usage for coroutine provider example 2020-09-03 16:59:11 -04:00
Roman Mogylatov
a497cb2527 Add container usage for callable provider example 2020-09-03 16:57:35 -04:00
Roman Mogylatov
1eb9020a4e Add container usage for all singleton provider examples 2020-09-03 16:56:01 -04:00
Roman Mogylatov
a7afa66e40 Add container usage for all factory provider examples 2020-09-03 16:51:12 -04:00
Roman Mogylatov
33b4416c2c Update readme 2020-09-03 16:28:11 -04:00
Roman Mogylatov
8b13a809e6 Edit feedback documentation page 2020-09-03 16:26:32 -04:00
Roman Mogylatov
ca986698e9 Update key features page and remove structure page 2020-09-03 16:20:04 -04:00
Roman Mogylatov
13286783d0
Delete README - coupling cohesion.png 2020-09-03 14:52:41 -04:00
Roman Mogylatov
b2b8d2f4cf
Add files via upload 2020-09-03 14:52:16 -04:00
Roman Mogylatov
f32363d259 Edit key features pages 2020-09-03 13:36:56 -04:00
Roman Mogylatov
f5758d842f Merge branch 'release/3.36.0' into master 2020-09-02 21:28:29 -04:00
Roman Mogylatov
063301a0b3 Bump version to 3.36.0 2020-09-02 21:28:09 -04:00
Roman Mogylatov
27ea3e3156 Update copyright year in the docs 2020-09-02 21:27:44 -04:00
Roman Mogylatov
6012d97a70 Remove not needed image from the docs 2020-09-02 21:27:24 -04:00
Roman Mogylatov
e29bf348ea Rename the container overriding docs page 2020-09-02 21:21:18 -04:00
Roman Mogylatov
580a9a66b5 Fix a typo in the custom provider docs 2020-09-02 21:21:07 -04:00
Roman Mogylatov
c2426d2a09 Update providers index page 2020-09-02 21:17:25 -04:00
Roman Mogylatov
dd2ded7321 Update documentation and example on creating a custom provider 2020-09-02 21:09:08 -04:00
Roman Mogylatov
aeace8cba5 Update documentation on injecting provided object attributes, items or method calls 2020-09-02 17:59:31 -04:00
Roman Mogylatov
e4ca126188 Update provider doc page headers 2020-09-02 17:33:02 -04:00
Roman Mogylatov
3eb7b9bc69 Add reference to provider overriding page 2020-09-02 17:25:20 -04:00
Roman Mogylatov
f8648adaf7 Update providers overriding documentation and rework examples 2020-09-02 16:59:25 -04:00
Roman Mogylatov
dcc59ab0f4 Merge branch 'release/3.35.1' into master 2020-09-01 21:58:30 -04:00
Roman Mogylatov
806bd31735 Bump version to 3.35.1 2020-09-01 21:58:13 -04:00
Roman Mogylatov
89fec6c905 Merge branch 'release/3.35.0' into master 2020-09-01 21:40:31 -04:00
Roman Mogylatov
0985635ea6 Bump version to 3.35.0 2020-09-01 21:40:14 -04:00
Roman Mogylatov
c4b33749d2
Providers docs update (#289)
* Update callable provider docs

* Update coroutine provider docs

* Edit object docs

* Edit list provider docs

* Edit configuration provider docs

* Edit selector provider docs

* Fix mypy stub of the ``DeclarativeContainer`` to specify the ``__init__`` interface

* Edit Dependency provider docs
2020-09-01 21:39:23 -04:00
Roman Mogylatov
995b2165df Update changelog 2020-09-01 16:05:58 -04:00
Roman Mogylatov
0bb30f91ef
Singleton docs update (#288)
* Update docblocks of factory provider examples

* Edit singleton docs
2020-09-01 16:04:48 -04:00
Roman Mogylatov
520945483f Merge branch 'release/3.34.0' into master 2020-08-31 21:29:26 -04:00
Roman Mogylatov
0d9aaaac0b Bump version to 3.34.0 2020-08-31 21:29:05 -04:00
Roman Mogylatov
1ad852d193
Factory provider docs update (#287)
* Update index page

* Update providers index page

* Make a little wording fix on containers index page

* Refactor factory provider docs header

* Update factory injection docs

* Update factory init injections example and picture

* Start work on underlying providers

* Finish the docs for factory arguments to the underlying providers

* Edit providers delegation section

* Edit section about specialized factory provider

* Edit abstract factory section

* Edit FactoryAggregate docs

* Add meta keywords and description
2020-08-31 21:26:21 -04:00
Roman Mogylatov
f83d8ce143 Merge branch 'release/3.33.0' into master 2020-08-26 22:25:41 -04:00
Roman Mogylatov
3c27cd6ab2 Bump version to 3.33.0 2020-08-26 22:25:22 -04:00
Roman Mogylatov
2e940adb50
Typing stubs (#286)
* Add basic setup

* Add more tests for factory

* Add mypy checks to CI

* Add mypy checks to makefile command

* Add typing for the factories

* Add stub for Callable providers

* Add typing module and object provider stubs

* Fix typing test issue

* Remove typing module

* Add Delegate stub

* Add stub for Dependency provider

* Add stub for ExternalDependency

* Add stubs for providers module functions

* Add stubs for the DependenciesContainer provider

* Add stub for the CallableDelegate provider

* Add stubs for Coroutine providers

* Add stubs for the configuration options

* Add stub for the FactoryDelegate

* Add stub for the FactoryAggregate provider

* Add singleton stubs

* Add stubs for singletons

* Add stub for the List provider

* Add stub for the Container provider

* Add stub for the Selector provider

* Add stubs for the dynamic container

* Add stub for the declarative container

* Add stubs for the extensions

* Add types module for explicit provider typing

* Set absolute import mode for the providers module and add types module test

* Skip typing test for Python 3.5

* Remove coroutine test from py35

* Fix py35 tests

* Add \n to the tox.ini
2020-08-26 22:24:20 -04:00
Roman Mogylatov
47f4279ccd Merge branch 'release/3.32.3' into master 2020-08-26 16:35:51 -04:00
Roman Mogylatov
15acccf48f Bump version to 3.32.3 2020-08-26 16:35:31 -04:00
Roman Mogylatov
0c868fc0db Merge branch 'release/3.32.2' into master 2020-08-26 16:25:20 -04:00
Roman Mogylatov
cc7ade89d7 Bump version to 3.32.2 2020-08-26 16:24:59 -04:00
Roman Mogylatov
9d85b63c3b Make a fix in the providers delegation example 2020-08-26 16:22:54 -04:00
Roman Mogylatov
2b30e172d1 Merge branch 'release/3.32.1' into master 2020-08-25 10:27:41 -04:00
Roman Mogylatov
3f94a900a4 Bump version to 3.32.1 2020-08-25 10:27:24 -04:00
Roman Mogylatov
6c7c9eaa47 Update example 2020-08-25 10:27:11 -04:00
Roman Mogylatov
0f952b5915 Merge branch 'release/3.32.0' into master 2020-08-24 13:38:25 -04:00
Roman Mogylatov
fcbab97db2 Bump version to 3.32.0 2020-08-24 13:38:08 -04:00
Roman Mogylatov
f5b97ca92e
Configuration option typed injections (#284)
* Add implementation and tests

* Add docs page and examples

* Revert the api_client miniapp accidental changes
2020-08-24 13:34:47 -04:00
Roman Mogylatov
69ebc19b5f Merge branch 'release/3.31.0' into master 2020-08-20 21:59:25 -04:00
Roman Mogylatov
cc8536b5e4 Bump version to 3.31.0 2020-08-20 21:59:09 -04:00
Roman Mogylatov
c05f2b2e42 Add JarnoRFB to the list of contributors 2020-08-20 21:53:16 -04:00
Roman Mogylatov
cf862fe8b5
Provided attributes (#282)
* Add sketch

* Cythonize MethodCaller

* Cythonize ItemGetter, AttributeGetter & ProvidedInstance providers

* Add docblock for .provided attribute

* Refactor repr methods

* Add .provided attribute to the Dependency provider

* Add tests for the .provided attribute to the majority of the providers

* Add docblock for the ProvidedInstance provider

* Add docblocks for the rest of the providers

* Add example of the provided instance usage

* Add tests for provided instance* providers

* Add complex provided instance example

* Update example provided_instance.py

* Add docs
2020-08-20 21:52:12 -04:00
Roman Mogylatov
50a9dda192 Merge branch 'release/3.30.4' into master 2020-08-16 01:16:40 -04:00
Roman Mogylatov
e15a6dbb1d Bump version to 3.30.4 2020-08-16 01:16:25 -04:00
Roman Mogylatov
597f6794a9 Merge branch 'release/3.30.3' into master 2020-08-16 01:13:47 -04:00
Roman Mogylatov
01a18bc2ff Bump version to 3.30.3 2020-08-16 01:13:32 -04:00
Roman Mogylatov
d2828519b4 Update container overriding docs 2020-08-16 01:10:08 -04:00
Roman Mogylatov
75c65f334e Update container provider type specialization docs 2020-08-16 00:53:37 -04:00
Roman Mogylatov
cfdcbaa77a Improve declarative and dynamic container docs 2020-08-15 22:09:41 -04:00
Roman Mogylatov
e0fa746d7f Update DI Demo 2 2020-08-15 11:01:58 -04:00
Roman Mogylatov
e479e2cb94 Update the declarative container docs 2020-08-14 16:27:17 -04:00
Roman Mogylatov
925801c73f Add overriding demo to the README 2020-08-14 15:49:31 -04:00
Roman Mogylatov
684745a6b4 Add providers overriding to demo 2 2020-08-14 15:31:33 -04:00
Roman Mogylatov
88866d596b Merge branch 'release/3.30.2' into master 2020-08-13 22:57:51 -04:00
Roman Mogylatov
ac6412bd41 Bump version to 3.30.2 2020-08-13 22:57:34 -04:00
Roman Mogylatov
32a4add687 Merge branch 'release/3.30.1' into master 2020-08-13 21:55:02 -04:00
Roman Mogylatov
f67dab1f03 Bump version to 3.30.1 2020-08-13 21:53:13 -04:00
Roman Mogylatov
3ddf131180 Merge branch 'release/3.30.0' into master 2020-08-12 17:07:01 -04:00
Roman Mogylatov
2f42de9fa1 Bump version to 3.30.0 2020-08-12 17:06:40 -04:00
Roman Mogylatov
5358dd85f1
Movie lister example rework (#280)
* Rework movie lister example app

* Code style fix

* Doc block fix

* Update the container

* Make second round of the refactoring

* Rename name to title

* Remove old movie lister docs from the examples

* Add fixtures generator output on success

* Update docblock in the entities module

* Update example readme

* Add CLI app tutorial

* Update some wording in the other tutorials

* Spread link to the tutorial

* Fix code indentation issue
2020-08-12 17:04:46 -04:00
Roman Mogylatov
ca18fea26c Merge branch 'release/3.29.0' into master 2020-08-10 22:32:40 -04:00
Roman Mogylatov
3c69b4683f Bump version to 3.29.0 2020-08-10 22:32:29 -04:00
Roman Mogylatov
bb1403b5e9 Update docs index and key features page 2020-08-10 22:29:25 -04:00
Roman Mogylatov
1c189c47e2
Update README.rst (#279)
* Make the message direct
* Emphasise the differences
* Change example code
* Add FAQ
2020-08-10 22:23:12 -04:00
Roman Mogylatov
d8102a825f Merge branch 'release/3.28.1' into master 2020-08-10 15:51:01 -04:00
Roman Mogylatov
ed2a795581 Bump version to 3.28.1 2020-08-10 15:50:51 -04:00
Roman Mogylatov
c9762ce6fa Fix typos in asyncio daemon tutorial 2020-08-10 15:49:44 -04:00
Roman Mogylatov
2bef0229d9 Merge branch 'release/3.28.0' into master 2020-08-08 14:49:26 -04:00
Roman Mogylatov
d3f3b58389 Bump version to 3.28.0 2020-08-08 14:49:08 -04:00
Roman Mogylatov
3a61457be7
Asyncio daemon tutorial (#278)
* Fix a typo in the docblock of the Configuration provider

* Update the changelog

* Add tutorial sections

* Switch to use https for httpbin.org requests

* Add what we are going to build section

* Fix ``Makefile`` to run ``aiohttp`` integration tests on Python 3.5+

* Add prerequisities and prepare the env sections

* Add logging, config and the dispacher sections

* Change logging

* Fix multiple typos in the ``flask`` and ``aiohttp`` tutorials

* Add the initial and dirty version

* Fix multiple typos in the ``flask`` and ``aiohttp`` tutorials

* Fix the 3.27.0 changelog

* Finish all the parts before the dispatcher

* Finish dispatcher section

* Update http monitor logging format

* Finish the tutorial

* Fix docblock in the dispatcher module

* Update changelog

* Add meta keywords and description
2020-08-08 14:48:05 -04:00
Roman Mogylatov
2ff36b44ab Merge branch 'release/3.27.0' into master 2020-08-06 16:46:08 -04:00
Roman Mogylatov
0cb45bbc1c Update the docblock of the example 2020-08-06 16:45:00 -04:00
Roman Mogylatov
5bf5a7651b Bump version to 3.27.0 2020-08-06 16:42:49 -04:00
Roman Mogylatov
9b30752da2 Update docs 2020-08-06 16:42:31 -04:00
Roman Mogylatov
4a8133204c
Factory deep init injections (#277)
* Add factory deep context providing

* Add example

* Add test
2020-08-06 16:33:06 -04:00
Roman Mogylatov
2fc3606671
Asyncio daemon example (#276)
* Add prototype

* Update .pydocstylerc

* Add tests

* Remove one of the tests

* Fix typo in the giphynav-aiohttp

* Add README

* Fix flake8
2020-08-05 22:11:26 -04:00
Roman Mogylatov
dc9c1dde3f Merge branch 'release/3.26.0' into master 2020-08-03 18:09:10 -04:00
Roman Mogylatov
1f302ec74c Bump version to 3.26.0 2020-08-03 18:08:53 -04:00
Roman Mogylatov
a202335519 Update giphynav-aiohttp to remove doubled "if not query" 2020-08-03 18:07:04 -04:00
Roman Mogylatov
ea1e79885c
274 Configuration provider redesign (#275)
* Get 1st stable version

* Remove prototype module

* Try fix copying

* Add config itemselector example

* Add doc blocks
2020-08-03 18:01:20 -04:00
Roman Mogylatov
459ff5fcf5 Merge branch 'release/3.25.1' into master 2020-07-30 13:53:58 -04:00
Roman Mogylatov
6fccb6eec1 Bump version to 3.25.1 2020-07-30 13:53:37 -04:00
Roman Mogylatov
45e6b943f6 Fix typos in aiohttp tutorial 2020-07-30 13:52:42 -04:00
Roman Mogylatov
299a7bca89 Merge branch 'release/3.25.0' into master 2020-07-29 22:20:53 -04:00
Roman Mogylatov
978ebda9eb Bump version to 3.25.0 2020-07-29 22:20:34 -04:00
Roman Mogylatov
d2f4585a8b
Aiohttp tutorial (#273)
* Make a code style change to the giphynav-aiohttp app

* Make minimal punctuation changes for the flask tutorial

* Add parts of http tutorial

* Fix few issues in the flask tutorial

* Make some cosmetic changes to test data

* Fix typo in flask tutorial

* Add more tutorial sections
2020-07-29 22:17:56 -04:00
Roman Mogylatov
97577d84e4
Revert "Aiohttp tutorial (#271)" (#272)
This reverts commit adcea61657.
2020-07-29 22:16:40 -04:00
Roman Mogylatov
adcea61657
Aiohttp tutorial (#271)
* Make a code style change to the giphynav-aiohttp app

* Make minimal punctuation changes for the flask tutorial

* Add parts of http tutorial

* Fix few issues in the flask tutorial

* Make some cosmetic changes to test data

* Fix typo in flask tutorial
2020-07-29 22:16:02 -04:00
Roman Mogylatov
577c7854da Merge branch 'release/3.24.1' into master 2020-07-29 12:18:24 -04:00
Roman Mogylatov
4ca385d73b Bump version to 3.24.1 2020-07-29 12:18:09 -04:00
Roman Mogylatov
469cb37302 Merge branch 'release/3.24.0' into master 2020-07-28 20:57:46 -04:00
Roman Mogylatov
c190e049b5 Bump version to 3.24.0 2020-07-28 19:26:41 -04:00
Roman Mogylatov
ed2fc618f1 Fix coverage 2020-07-28 19:25:02 -04:00
Roman Mogylatov
e0d81c2d28
Aiohttp integration (#270)
* Add aiohttp extension module

* Add giphynav-aiohttp app

* Add missing docstrings

* Remove print() call

* Remove not needed import from flask extension tests

* Improve coroutine provider tests

* Add aiohttp extension tests

* Update tox.ini

* Add aiohttp extras

* Try fix Python 3.4 tests

* Try fix 3.6 tests

* Stop running coroutine tests for Python 3.4

* Rename tests

* Remove type hints

* Fix pypy and change python version for coverage job to 3.8

* Fix coveralls job

* Try fix Python 3.4, 3.5 tests

* Make coverage job to run 3.5+ tests

* Add tests

* Add readme

* Update the readmes

* Add API docs

* Add API docs page

* Update changelog
2020-07-28 19:19:05 -04:00
Roman Mogylatov
bed547cc91 Merge branch 'release/3.23.2' into master 2020-07-23 20:49:32 -04:00
Roman Mogylatov
8f5ea52303 Bump version to 3.23.2 2020-07-23 20:49:08 -04:00
Roman Mogylatov
adf77c2399
Fix flask tutorial (#269)
* Fix highlight

* Fix flask tutorial rst issues

* Fix some wording
2020-07-23 20:47:35 -04:00
Roman Mogylatov
4a1caf7300 Merge branch 'release/3.23.1' into master 2020-07-22 12:17:57 -04:00
Roman Mogylatov
00d91ae829 Bump version to 3.23.1 2020-07-22 12:17:37 -04:00
Roman Mogylatov
1f115111b2
Dependency provider issue with abc (#267)
* Fix the issue

* Add the test

* Update tests

* Update changelog

* Update tests
2020-07-22 12:14:26 -04:00
Roman Mogylatov
cfbed20a05 Merge branch 'release/3.23.0' into master 2020-07-20 17:02:52 -04:00
Roman Mogylatov
93adbe5207 Bump version to 3.23.0 2020-07-20 17:02:32 -04:00
Roman Mogylatov
1674cecc8d
Flask tutorial (#265)
* Add a piece of the tutorial

* Add "Make it pretty" tutorial step

* Add section about github client setup

* Make minor fixes

* Add search service section + table of contents

* Make various fixes

* Make more fixes

* Update make the search section

* Update ghnav-flask example & README

* Update base.html markup

* Finish section: Make the search work

* Update ghnav-flask screenshot

* Update tutorials

* Add flaks tutorial link to the DI in Python page
2020-07-20 16:58:18 -04:00
Roman Mogylatov
3ee629eb5d Merge branch 'release/3.22.0' into master 2020-07-18 00:45:22 -04:00
Roman Mogylatov
78b7be218b Bump version to 3.22.0 2020-07-18 00:45:06 -04:00
Roman Mogylatov
b3c0a79725 Update the changelog 2020-07-18 00:44:11 -04:00
Roman Mogylatov
6eff213a68
Migrate to alabaster (#264)
* Add bootstrap and remove created at from ghnav-flask app

* Update readme

* Add logo to the docs

* Update key features description

* Update README

* Change headers of API docs

* Add alabaster theme config

* Update docs index

* Add tutorials section

* Update what is DI page

* Update DI in Python page

* Update tutorials index page

* Update provider docs

* Update container docs

* Update examples docs
2020-07-18 00:40:14 -04:00
Roman Mogylatov
8a2a88ccc9 Merge branch 'release/3.21.2' into master 2020-07-13 23:29:49 -04:00
Roman Mogylatov
8b2486c5e5 Bump version to 3.21.2 2020-07-13 23:29:32 -04:00
Roman Mogylatov
f05c6bef29 Merge branch 'release/3.21.1' into master 2020-07-13 23:10:18 -04:00
Roman Mogylatov
5ada7f24dd Bump version to 3.21.1 2020-07-13 23:09:42 -04:00
Roman Mogylatov
0c77e73d51 Merge branch 'release/3.21.0' into master 2020-07-13 22:50:22 -04:00
Roman Mogylatov
73cfc873ce Bump version to 3.21.0 2020-07-13 22:50:02 -04:00
Roman Mogylatov
72147b664e Re-design Flask integration 2020-07-13 22:45:15 -04:00
Roman Mogylatov
359dce2978 Make cosmetic fixes for `Selector` provider docs 2020-07-13 15:36:07 -04:00
Roman Mogylatov
70d6e8c68f Merge branch 'release/3.20.1' into master 2020-07-11 13:19:41 -04:00
Roman Mogylatov
24addb65eb Fix README 2020-07-11 13:18:52 -04:00
Roman Mogylatov
a2ac13c551
Update README.rst 2020-07-11 13:15:27 -04:00
Roman Mogylatov
a782170579 Update README 2020-07-11 13:10:46 -04:00
Roman Mogylatov
0b906be150
Update README.rst 2020-07-11 13:08:07 -04:00
Roman Mogylatov
b6bf490239 Update README 2020-07-11 13:07:28 -04:00
Roman Mogylatov
603ecf0838 Update README 2020-07-11 13:06:16 -04:00
Roman Mogylatov
8dc1e9d4a4 Update README with unicode for emoji 2020-07-11 13:02:30 -04:00
Roman Mogylatov
3c2b6bb558 Merge branch 'release/3.20.1' into master 2020-07-11 12:43:15 -04:00
Roman Mogylatov
4f753c8fd3 Bump version to 3.20.1 2020-07-11 12:42:55 -04:00
Roman Mogylatov
21cdd0aa3c Merge branch 'release/3.20.0' into master 2020-07-11 12:16:31 -04:00
Roman Mogylatov
d6176dc754 Bump version to 3.20.0 2020-07-11 12:16:08 -04:00
Roman Mogylatov
fa469618dd
Readme update (#263)
* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Add files via upload

* Update README.rst

* Rename Blank Diagram (1).svg to di-map.svg

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Add files via upload

* Rename Blank Diagram (2).svg to di-map2.svg

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Add files via upload

* Add files via upload

* Rename README.svg to di-map3.svg

* Update README.rst

* Add files via upload

* Rename README - Page 3.svg to di-map4.svg

* Update README.rst

* Add files via upload

* Rename README - Copy of Page 3.svg to di-map5.svg

* Update README.rst

* Delete di-map.svg

* Delete di-map2.svg

* Delete di-map3.svg

* Delete di-map4.svg

* Update README.rst

* Update README.rst

* Add Github Navigator - Flask application

* Do more refactoring for ghnav-flask

* More refactoring

* Update README

* Add tests

* Update readme

* Add Flask extension

* Add Factory.provides attribute

* Add Flask extension module

* User flask extension in githubnavigator example

* Add README for ghnav-flask

* Update ghnav-flask README

* Update ghnav-flask README

* Update README with ghnav container example

* Move ghnav-flask to miniapps/ folder

* Fix auth token reading from env for ghnav-flask

* Update readme

* Fix ghnav-flask linter errors

* Add downloads and wheel badge

* Add tests for flask extension

* Fix flask tests

* Add requirements-ext.txt installation to tox.ini

* Add API docs for ext.flask module

* Update setup.py

* Add Flask to the list of keywords

* Update badges on docs README

* Update docs README title

* Fix ext.flask tests

* Fix syntax of ext.flask for Python 2.7, 3.4, 3.5

* Fix syntax of ext.flask for Python 2.7, 3.4, 3.5

* Fix imports in ext.flask for Python 2.7, 3.4, 3.5

* Update ghfnav-flask README

* Update ghfnav-flask README

* Remove setting of empty github token

* Add flask extras

* Update requirements

* Update requirements

* Add flask extra to python 3.4 tox.ini

* Update changelog

* Update changelog
2020-07-11 12:15:00 -04:00
Roman Mogylatov
f4c713fc22 Merge branch 'release/3.19.2' into master 2020-07-02 22:08:32 -04:00
Roman Mogylatov
a8135c0628 Bump version to 3.19.2 2020-07-02 22:08:12 -04:00
Roman Mogylatov
f130d41dbc
Logo (#261)
* Try logo placement

* Remove readme header

* Experiment with badges

* Add space

* Update logo

* Remove spaces

* Update README.rst

* Remove header

* Update README.rst

* Move logo to wiki

* Add github badges

* Remove github badges

* Update docs index page
2020-07-02 22:07:07 -04:00
Roman Mogylatov
ec3be85cf7 Merge branch 'release/3.19.1' into master 2020-07-01 23:20:42 -04:00
Roman Mogylatov
5e84f3145e Update makefile 2020-07-01 23:20:28 -04:00
Roman Mogylatov
0da9f2c6b5 Update travis config to publish to real pypi 2020-07-01 23:18:41 -04:00
Roman Mogylatov
cc90f66dc8 Bump version to 3.19.1 2020-07-01 23:17:29 -04:00
Roman Mogylatov
4a82aa18c3
Wheels (#260)
* Update .travis.yml

* Update .travis.yml

* Add cibuildwheel jobs

* Point twine to testpypi

* Add test suffix to version

* Try to fix windows builds

* Change version to 3.19.0.a2

* Remove build dependencies from dev requirements

* Add condition to trigger build on tags

* Bump version to 3.19.0a3

* Target sdist job to publish to testpypi

* Upgrade travis config

* Bump version to 3.19.0a4

* Return version

* Update changelog

* Update makefile
2020-07-01 23:16:38 -04:00
Roman Mogylatov
75a9f6faf0 Update changelog 2020-06-30 17:32:16 -04:00
Roman Mogylatov
18bac2b1d6 Fix travis config warnings 2020-06-30 17:31:01 -04:00
Roman Mogylatov
f84daf6467 Add default os and dist to travis config 2020-06-30 17:04:47 -04:00
Roman Mogylatov
dfe61826b0 Rename matrix to jobs at travis config 2020-06-30 17:02:54 -04:00
Roman Mogylatov
0126fdb522 Remove sudo from travis config 2020-06-30 17:01:52 -04:00
Roman Mogylatov
f8b78443f9 Encrypt slack token at travis config 2020-06-30 17:00:23 -04:00
Roman Mogylatov
1ca6f303c9 Update changelog 2020-06-30 16:44:01 -04:00
Roman Mogylatov
8681500236
Start using twine for dist uploading to PyPI (#259) 2020-06-30 16:40:30 -04:00
Roman Mogylatov
17621d9fd7 Merge branch 'release/3.19.0' into master 2020-06-29 16:41:32 -04:00
Roman Mogylatov
1a5e7baf7b Bump version to 3.19.0 2020-06-29 16:34:05 -04:00
Roman Mogylatov
a0a3da8f72 Improve List and Configuration provider docs 2020-06-29 16:32:48 -04:00
Roman Mogylatov
2513d1f600
Selector provider (#258)
* Add Selector provider

* Add Selector provider example

* Add tests for selector provider

* Update changelog

* Add pydocstyle ignore D101 for examples

* Fix repr() test

* Update changelog

* Add D203,D213 to examples pydocstyle ignore

* Add selector provider docs
2020-06-29 16:32:12 -04:00
Roman Mogylatov
783be3ad36 Merge branch 'release/3.18.1' into master 2020-06-25 23:49:37 -04:00
Roman Mogylatov
284b258879 Add docs for environment varibles interpolation in the Configuration provider 2020-06-25 23:48:55 -04:00
Roman Mogylatov
7491fc05a2 Fix ini files parsing 2020-06-25 23:37:01 -04:00
Roman Mogylatov
1cd25e701f Add interpolation of environment variables for Configuration provider 2020-06-25 23:16:19 -04:00
Roman Mogylatov
5718140a82 Merge branch 'release/3.18.0' into master 2020-06-25 18:06:58 -04:00
Roman Mogylatov
525ddbc24c Bump version to 3.18.0 2020-06-25 18:06:37 -04:00
Roman Mogylatov
f176b02045 Add flake8 config 2020-06-25 18:01:15 -04:00
Roman Mogylatov
62e1995a7d Add configuration provider docs 2020-06-25 17:12:16 -04:00
Roman Mogylatov
507a832bb8 Add Configuration.from_env() method + refactoring 2020-06-25 12:50:42 -04:00
Roman Mogylatov
3217feb73b Update providers.pyx code style 2020-06-24 21:27:40 -04:00
Roman Mogylatov
e5275cf3f2 Skip yaml testing for on Python 3.4 2020-06-24 21:23:29 -04:00
Roman Mogylatov
65db4f2b1d Fix code style issue 2020-06-24 21:23:05 -04:00
Roman Mogylatov
ad2d8155d4 Remove yaml stub in providers module 2020-06-24 21:13:37 -04:00
Roman Mogylatov
c8b0fa22af Add yaml extras install to tox.ini 2020-06-24 21:07:57 -04:00
Roman Mogylatov
e22edcdadd Restore configuration methods 2020-06-24 21:04:30 -04:00
Roman Mogylatov
0dad8727cf Fix setup.py 2020-06-24 21:01:33 -04:00
Roman Mogylatov
1a23b8b6f5 Try type(dict) fix 2020-06-24 17:38:52 -04:00
Roman Mogylatov
50d8363650 Pin virtualenv to 20.0.23 2020-06-24 17:26:58 -04:00
Roman Mogylatov
52c98bbe49 Comment yaml-related code 2020-06-24 17:16:46 -04:00
Roman Mogylatov
f7871dfc49 Update extras in tox.ini 2020-06-24 16:46:48 -04:00
Roman Mogylatov
597f5d772f Add default value for name argument of Configuration provider 2020-06-24 16:40:53 -04:00
Roman Mogylatov
a76744805a Add Configuration.from_yaml method 2020-06-24 16:29:44 -04:00
Roman Mogylatov
2c43a1c426 Remove undocumented positional parameter of DependenciesContainer provider 2020-06-24 14:39:07 -04:00
Roman Mogylatov
feab6b6814 Revert "Add overriding logic for Container provider"
This reverts commit b727be3f9a.
2020-06-24 13:24:57 -04:00
Roman Mogylatov
b727be3f9a Add overriding logic for Container provider 2020-06-24 12:41:18 -04:00
Roman Mogylatov
f95dadfc23 Add Configuration.from_dict() method 2020-06-23 18:09:20 -04:00
Roman Mogylatov
a985952d0c Fix Configuration.from_ini() to support Python 2 2020-06-23 16:53:22 -04:00
Roman Mogylatov
87bb5ff97d Add Configuration.from_ini() method 2020-06-23 16:46:24 -04:00
Roman Mogylatov
3a0c746430 Merge branch 'release/3.17.1' into master 2020-06-23 12:48:37 -04:00
Roman Mogylatov
1e13727a94 Bump version to 3.17.1 2020-06-23 12:48:01 -04:00
Roman Mogylatov
2fd216bb5a Hotfix dynamic container deep-copying 2020-06-23 12:47:48 -04:00
Roman Mogylatov
827f9b57bb Merge branch 'release/3.17.0' into master 2020-06-23 12:14:28 -04:00
Roman Mogylatov
69e2230b80 Bump version to 3.17.0 2020-06-23 12:14:06 -04:00
Roman Mogylatov
c8b781e744
Container provider (#256)
* Add unit tests

* Add Container provider

* Update changelog
2020-06-22 22:45:16 -04:00
Roman Mogylatov
e6f096270e
Config linking (#255)
* Add config linking test

* Add provider linking

* Update changelog
2020-06-22 21:52:00 -04:00
Roman Mogylatov
86021f2948 Merge branch 'release/3.16.1' into master 2020-06-16 22:34:36 -04:00
Roman Mogylatov
7c3d961ae7 Bump version to 3.16.1 2020-06-16 22:34:19 -04:00
Roman Mogylatov
761fc84658 Update disqus.js 2020-06-16 22:32:47 -04:00
Roman Mogylatov
d90a490987 Add RobinsonMa to the list of contributors 2020-06-16 22:25:41 -04:00
Roman Mogylatov
eadac4b1cc Fix warnings in API docs 2020-06-16 22:22:06 -04:00
RobinsonMa
c136663071
Update singleton_thread_locals.py (#252)
* Update singleton_thread_locals.py

fix

* Update singleton_thread_locals.py

* Update singleton_thread_locals.py
2020-06-16 21:53:00 -04:00
Roman Mogylatov
a0d4af15e9 Fix warnings at changelog 2020-06-16 21:40:01 -04:00
Roman Mogylatov
877275e7fc Fix warning at docs/conf.py 2020-06-16 21:39:34 -04:00
Roman Mogylatov
29243ccdda Fix make docs-live 2020-06-16 21:39:11 -04:00
Roman Mogylatov
cc1043eb82 Fix disqus.js 2020-06-16 21:38:54 -04:00
Roman Mogylatov
efd6e3e7e5 Merge branch 'release/3.16.0' into master 2020-06-14 17:50:28 -04:00
Roman Mogylatov
dd7c951ea6 Bump version to 3.16.0 2020-06-14 17:49:57 -04:00
Roman Mogylatov
8f2c397413 Add support of six 1.15.0 2020-06-14 17:43:06 -04:00
Roman Mogylatov
af7297ce71 Update Cython version 2020-06-14 17:38:24 -04:00
Roman Mogylatov
b6f6f63764 Add docs-live command to makefile 2020-06-14 17:35:25 -04:00
Roman Mogylatov
2beafb9a51
List provider (#251)
* Add List provider

* Add List provider example

* Add List provider unit tests

* Add docs

* Upstream changes from develop

* Update API docs

* Update unit tests

* Add support of positional context argument injections

* Update changelog
2020-06-14 17:32:12 -04:00
Roman Mogylatov
d8ecd28b22 Add Bruno P. Kinoshita to the list of contributors 2020-06-13 23:28:40 -04:00
Bruno P. Kinoshita
910dec38a4
Fix a few typos (#250)
* Fix a few typos

* Spell, grammar checkers on docs
2020-06-13 22:24:32 -04:00
Roman Mogylatov
ebd98bebe9 Merge branch 'release/3.15.6' into master 2020-02-18 17:53:10 -05:00
Roman Mogylatov
fac768496e Bump version to 3.15.6 2020-02-18 17:52:46 -05:00
Roman Mogylatov
b3eb05f705 Merge branch 'release/3.15.5' into master 2020-02-18 17:51:36 -05:00
Roman Mogylatov
6c81568888 Bump version to 3.15.5 2020-02-18 17:50:56 -05:00
Roman Mogylatov
a0349305db Update downloads link 2020-02-18 17:49:37 -05:00
Roman Mogylatov
68a0f4b5f0 Add downloads badge 2020-02-18 17:48:20 -05:00
Roman Mogylatov
5e6a4ce1ec Merge branch 'release/3.15.4' into master 2020-01-26 20:37:43 -05:00
Roman Mogylatov
b00edad1b9 Bump version to 3.15.4 2020-01-26 20:37:13 -05:00
Roman Mogylatov
92e91a3fdf Merge branch 'release/3.15.3' into master 2020-01-26 20:33:13 -05:00
Roman Mogylatov
78dd3ec744 Add more docs fixes for 3.15.3 2020-01-26 20:32:16 -05:00
Roman Mogylatov
f8ddf1b19b Bump version to 3.15.3 2020-01-26 19:53:06 -05:00
Roman Mogylatov
0dae54df18 Merge branch 'release/3.15.2' into master 2020-01-26 19:34:04 -05:00
Roman Mogylatov
7ce170a1d9 Bump version to 3.15.2 2020-01-26 19:33:28 -05:00
Roman Mogylatov
363b87fd74 Merge branch 'release/3.15.1' into master 2020-01-26 19:17:46 -05:00
Roman Mogylatov
b09868233c Bump version to 3.15.1 2020-01-26 19:17:03 -05:00
Roman Mogylatov
febae1b64c Update engines-cars example 2020-01-26 19:13:57 -05:00
Roman Mogylatov
b9f68d18a9 Fix README typos 2020-01-26 19:04:23 -05:00
Roman Mogylatov
a58e300707 Merge branch 'release/3.15.0' into master 2020-01-26 18:56:37 -05:00
Roman Mogylatov
4d9d12a2ed Bump version to 3.15.0 2020-01-26 18:55:33 -05:00
Roman Mogylatov
c20202a23d Refactor passlib password hasing example 2020-01-26 18:55:04 -05:00
Roman Mogylatov
cf44e5815d Refactor example modules in Python3-ish way 2020-01-26 18:41:36 -05:00
Roman Mogylatov
06ff4bbbe4 Clean up tox.ini file 2020-01-26 15:15:50 -05:00
Roman Mogylatov
5c1174fad6
PyPy 3 support (#242)
* Add PyPy 3 to travis file

* Add record to changelog
2020-01-26 15:10:51 -05:00
Roman Mogylatov
953f93631b
Python 3.8 support (#241)
* Add Python 3.8 test environment

* Add Python 3.8 classifier

* Update max compatible version of six to 1.13.0

* Update max compatible version of six to 1.14.0

* Add record to the changelog
2020-01-26 15:00:21 -05:00
Roman Mogylatov
ed8053fce1 Refactor changelog 2020-01-26 14:28:15 -05:00
Roman Mogylatov
b876d001df Regenerate C sources using Cython 0.29.14 2020-01-26 14:27:23 -05:00
Roman Mogylatov
23642e49f4 Fix PEP257 doc block errors in example modules. 2020-01-26 14:22:43 -05:00
Roman Mogylatov
2c7b082301 Merge branch 'release/3.14.12' into master 2019-10-09 10:46:26 -04:00
Roman Mogylatov
d58a10a2c5 Bump version to 3.14.12 2019-10-09 10:46:08 -04:00
Roman Mogylatov
08de710b2f
235 Fix Delegate cannot be used in overridden container (#236)
* Add test for bug #235

* Fix issue + refactoring

* Update changelog
2019-10-09 10:45:14 -04:00
Roman Mogylatov
8026e106a5 Merge branch 'release/3.14.11' into master 2019-10-08 14:46:50 -04:00
Roman Mogylatov
fb264a8379 Bump version to 3.14.11 2019-10-08 14:46:26 -04:00
Roman Mogylatov
7e61412b8a
231 Fix object provider copies provided object issue (#233)
* Add test that reproduces the issue

* Fix the issue

* Add a note about fix in changelog
2019-10-08 14:45:12 -04:00
Roman Mogylatov
2684b79103 Merge branch 'release/3.14.10' into master 2019-08-17 21:24:42 -04:00
Roman Mogylatov
e48af3212e Make 3.14.10 micro release 2019-08-17 21:24:26 -04:00
Roman Mogylatov
75ffa8dd93 Merge branch 'release/3.14.9' into master 2019-08-17 21:09:31 -04:00
Roman Mogylatov
31642f4eca Update changelog 2019-08-17 21:08:53 -04:00
Roman Mogylatov
642fd7397e Bump version to 3.14.9 2019-08-17 21:08:42 -04:00
Roman Mogylatov
2b51a6e5f2 Add supakeen to the list of contributors 2019-08-17 21:07:19 -04:00
supakeen
3069910606 Minor English nitpicking. (#227) 2019-08-17 20:57:10 -04:00
Roman Mogylatov
0568e402a1 Merge branch 'release/3.14.8' into master 2019-07-29 15:25:16 -04:00
Roman Mogylatov
e5f437ff8d Add changelog for 3.14.8 2019-07-29 15:24:55 -04:00
Roman Mogylatov
0ac1a10336
Regenerate C sources using Cython 0.29.13 (#226) 2019-07-29 15:24:00 -04:00
Roman Mogylatov
e1b9303797 Merge branch 'release/3.14.7' into master 2019-06-07 10:03:40 -04:00
Roman Mogylatov
ecae4c2296 Bump version to 3.14.7 2019-06-07 10:03:11 -04:00
Dmitry
bcbdc7d6ad Fix typo (#221)
* Fix typo. (#214)

* Fix typo

* Update the title tildas
2019-06-07 09:55:30 -04:00
Roman Mogylatov
35cb351e72 Merge branch 'release/3.14.6' into master 2019-05-09 15:02:28 -04:00
Roman Mogylatov
3ced0ed37a Bump version to 3.14.6 2019-05-09 14:58:54 -04:00
Roman Mogylatov
215b45b442
FactoryAggregate copying issue fix (#220)
* Add test

* Implement deepcopy handler for FactoryAggregate provider

* Add more granularity for the test

* Update changelog

* Refactor test
2019-05-09 14:58:04 -04:00
Roman Mogylatov
cae4d8cdf2
Update Cython to 0.29.7 (#219) 2019-05-09 14:35:27 -04:00
Roman Mogylatov
d04fe41eb1 Merge branch 'release/3.14.5' into master 2019-03-21 22:23:23 -04:00
Roman Mogylatov
b2a3404007 Bump version to 3.14.5 2019-03-21 22:22:57 -04:00
Roman Mogylatov
efdae17b57 Regenerate C sources using Cython 0.29.6 2019-03-21 22:22:09 -04:00
Roman Mogylatov
a39f873693 Add Jeroen Rietveld to the list of contributors 2019-03-21 22:11:13 -04:00
Roman Mogylatov
87011a7280 Update changelog 2019-03-21 22:10:53 -04:00
Jeroen Rietveld
72d5741ece Bugfix thread local singleton reset (#218)
* Fix issue causing ThreadLocalSingleton provider to return None after reset

* Add test for ThreadLocalSingleton provider reset functionality
2019-03-21 22:04:20 -04:00
Roman Mogylatov
6c9bff116a Merge branch 'release/3.14.4' into master 2019-01-05 21:39:00 -05:00
Roman Mogylatov
69602dc3de Bump version to 3.14.4 2019-01-05 21:38:07 -05:00
Roman Mogylatov
673796b4b7 Add Vlad Ghita to the list of contributors 2019-01-05 21:37:50 -05:00
Vlad Ghita
9ef616a148 Fix typo. (#214) 2019-01-05 17:07:23 -05:00
Vlad Ghita
5bb49b9af5 Fix typo. (#214) 2019-01-04 08:11:55 -05:00
Roman Mogylatov
5cf5bdda24 Merge branch 'release/3.14.3' into master 2018-12-22 21:07:52 +02:00
Roman Mogylatov
5d94fa96b3 Bump version to 3.14.3 2018-12-22 21:02:00 +02:00
Roman Mogylatov
7c47c67808
Update Cython to 0.29.2 (#213)
* Update Cython to 0.29.2

* Regenerate C sources

* Update changelog
2018-12-22 21:00:30 +02:00
Roman Mogylatov
2792d02455
Add support of six 1.12 (#212)
* Increase range of six versions to 1.12

* Update changelog
2018-12-22 20:50:25 +02:00
Roman Mogylatov
f4f773be5a
Copying providers with sys stream injections (#211)
* Add fix + tests

* Update changelog
2018-12-22 20:37:53 +02:00
Roman Mogylatov
2d0a91efbf Merge branch 'release/3.14.2' into master 2018-11-08 23:13:11 +02:00
Roman Mogylatov
dc85b2e981 Set Cython language_level=2 2018-11-08 23:12:50 +02:00
Roman Mogylatov
15a3031da6 Merge branch 'release/3.14.1' into master 2018-11-08 22:59:42 +02:00
Roman Mogylatov
1f2c626b03 Bump version to 3.14.1 2018-11-08 22:59:21 +02:00
Roman Mogylatov
ce3ea6c9c1 Upgrade to Cython 0.29 2018-11-08 22:58:17 +02:00
Roman Mogylatov
3e73555869 Remove assertEquals from tests 2018-11-08 22:55:01 +02:00
Roman Mogylatov
b1e166dcd5 Fix issue #208 2018-11-08 22:49:41 +02:00
Roman Mogylatov
62b0f914b9 Merge branch 'release/3.14.0' into master 2018-10-19 13:01:54 +03:00
Roman Mogylatov
84e2fd717f Bump version to 3.14.0 2018-10-19 13:00:55 +03:00
Roman Mogylatov
ea0f9d8306 Update doc blocks with *args and **kwargs 2018-10-19 12:56:41 +03:00
Roman Mogylatov
9a785de4b5
Coroutine provider (#206)
* Add coroutine provider examples

* Add coroutine provier

* Update changelog

* Update static analysis travis jobs to python 3.7

* Update coroutine provider implementation for python 3.4

* Update static analysis travis jobs to python 3.6

* Make pycode style happy

* Add tests for coroutine providers

* Make coroutine tests python 2 syntax friendly

* Split tests to python2 and python3

* Refactor coroutine provider tests

* Modify pypy tests running command

* Update coroutine provider docs
2018-10-18 19:39:19 +03:00
Roman Mogylatov
ac0e5eb26a Regenerate C sources using Cython 0.28.5 2018-10-15 07:46:27 +03:00
Roman Mogylatov
829eed2222 Merge branch 'release/3.13.2' into master 2018-09-02 21:02:16 +03:00
Roman Mogylatov
b3a6aeae41 Bump version to 3.13.2 2018-09-02 21:01:19 +03:00
Tobias Happ
bd855ace58 Adds tests in MANIFEST.in (#204) 2018-09-02 20:54:06 +03:00
Roman Mogylatov
b2b69b34bb Add benchmark of Factory provider 2018-08-20 22:14:52 +03:00
Roman Mogylatov
1cd3bd18e8 Merge branch 'release/3.13.1' into master 2018-08-17 00:28:18 +03:00
Roman Mogylatov
883fc951a3 Bump version to 3.13.1 2018-08-17 00:27:49 +03:00
741 changed files with 42425 additions and 84984 deletions

View File

@ -1,7 +0,0 @@
[run]
source = src/dependency_injector
omit = tests/unit
plugins = Cython.Coverage
[html]
directory=reports/unittests/

View File

@ -0,0 +1,29 @@
---
description: Code in Python and Cython
globs:
alwaysApply: false
---
- Follow PEP 8 rules
- When you write imports, split system, 3rd-party, and local imports with a new line
- Have two empty lines between the import block and the rest of the code
- Have an empty line (\n) at the end of every file
- If a file is supposed to be run, always add ``if __name__ == 'main'``
- Always follow a consistent pattern of using double or single quotes
- When there is a class without a docblock, leave one blank line before its members, e.g.:
```python
class Container(containers.DeclarativeContainer):
service = providers.Factory(Service)
```
- Avoid shortcuts in names unless absolutely necessary, exceptions:
```
arg
args
kwarg
kwargs
obj
cls
```
- Avoid inline comments unless absolutely necessary

View File

@ -0,0 +1,7 @@
---
description: Build and run tests
globs:
alwaysApply: false
---
- Use Makefile commands to build, test, lint and other similar operations when they are available.
- Activate virtualenv before running any commands by ``. venv/bin/actvate``

View File

@ -0,0 +1,8 @@
---
description: Run examples
globs:
alwaysApply: false
---
- When you run an example from the ``examples/`` folder, switch to the example folder and run it from there.
- If there are instructions on running the examples or its tests in readme, follow them
- Activate virtualenv before running any commands by ``. venv/bin/actvate``

12
.deepsource.toml Normal file
View File

@ -0,0 +1,12 @@
version = 1
test_patterns = ["tests/**/test_*.py"]
exclude_patterns = ["docs/**"]
[[analyzers]]
name = "python"
enabled = true
[analyzers.meta]
runtime_version = "3.x.x"

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{py,pyi,pxd,pyx}]
ij_visual_guides = 80,88

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: rmk135

131
.github/workflows/publishing.yml vendored Normal file
View File

@ -0,0 +1,131 @@
name: Publishing
on:
workflow_dispatch:
push:
tags:
- '*'
jobs:
tests:
name: Run tests
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.13
- run: pip install tox
- run: tox
env:
TOXENV: 3.13
linters:
name: Run linters
runs-on: ubuntu-24.04
strategy:
matrix:
toxenv: [flake8, pydocstyle, mypy, pylint]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.13
- run: pip install tox
- run: tox
env:
TOXENV: ${{ matrix.toxenv }}
build-sdist:
name: Build source tarball
needs: [tests, linters]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.13
- run: |
python -m pip install --upgrade build
python -m build --sdist
- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: ./dist/*
build-wheels:
name: Build wheels
needs: [tests, linters]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-24.04, ubuntu-24.04-arm, windows-2022, macos-14]
env:
CIBW_ENABLE: pypy
CIBW_ENVIRONMENT: >-
PIP_CONFIG_SETTINGS="build_ext=-j4"
DEPENDENCY_INJECTOR_LIMITED_API="1"
CFLAGS="-g0"
steps:
- uses: actions/checkout@v3
- name: Build wheels
uses: pypa/cibuildwheel@v3.0.0
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl
test-publish:
name: Upload release to TestPyPI
needs: [build-sdist, build-wheels]
runs-on: ubuntu-latest
environment: test-pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
publish:
name: Upload release to PyPI
needs: [build-sdist, build-wheels, test-publish]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@release/v1
publish-docs:
name: Publish docs
needs: [publish]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.13
- run: pip install awscli
- run: pip install -r requirements-doc.txt
- run: pip install -e .
- run: (cd docs && make clean html)
- run: |
aws s3 sync docs/_build/html s3://python-dependency-injector-docs --delete
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --path "/*" > /dev/null
echo "Cache invalidation triggered"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}

67
.github/workflows/tests-and-linters.yml vendored Normal file
View File

@ -0,0 +1,67 @@
name: Tests and linters
on: [push, pull_request, workflow_dispatch]
jobs:
test-on-different-versions:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install tox
- run: tox
env:
DEPENDENCY_INJECTOR_LIMITED_API: 1
TOXENV: ${{ matrix.python-version }}
test-different-pydantic-versions:
name: Run tests with different pydantic versions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- run: pip install tox
- run: tox -e pydantic-v1,pydantic-v2
test-coverage:
name: Run tests with coverage
runs-on: ubuntu-latest
env:
DEPENDENCY_INJECTOR_DEBUG_MODE: 1
PIP_VERBOSE: 1
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.12
- run: pip install tox
- run: tox -vv
env:
TOXENV: coveralls
linters:
name: Run linters
runs-on: ubuntu-latest
strategy:
matrix:
toxenv: [flake8, pydocstyle, mypy, pylint]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.13
- run: pip install tox
- run: tox
env:
TOXENV: ${{ matrix.toxenv }}

21
.gitignore vendored
View File

@ -15,6 +15,7 @@ lib64/
parts/
sdist/
var/
wheelhouse/
*.egg-info/
.installed.cfg
*.egg
@ -36,6 +37,7 @@ reports/
.cache
nosetests.xml
coverage.xml
.hypothesis/
# Translations
*.mo
@ -54,7 +56,7 @@ target/
.idea/
# Virtualenv
venv/
venv*/
# SQLite
*.db
@ -62,10 +64,13 @@ venv/
# Vim Rope
.ropeproject/
# C extensions
src/dependency_injector/*.h
src/dependency_injector/*.so
src/dependency_injector/containers/*.h
src/dependency_injector/containers/*.so
src/dependency_injector/providers/*.h
src/dependency_injector/providers/*.so
# Cython artifacts
src/**/*.c
src/**/*.h
src/**/*.so
src/**/*.html
# Workspace for samples
.workspace/
.vscode/

View File

@ -1,49 +0,0 @@
[MASTER]
# Add <file or directory> to the black list. It should be a base name, not a
# path. You may set this option multiple times.
ignore=utils,tests
[MESSAGES CONTROL]
# Disable the message(s) with the given id(s).
# disable-msg=
[SIMILARITIES]
# Minimum lines number of a similarity.
min-similarity-lines=5
[TYPECHECK]
ignore-mixin-members=yes
# ignored-classes=
zope=no
# generated-members=providedBy,implementedBy,rawDataReceived
[DESIGN]
# Maximum number of arguments for function / method
max-args=10
# Maximum number of locals for function / method body
max-locals=20
# Maximum number of return / yield for function / method body
max-returns=10
# Maximum number of branch for function / method body
max-branchs=10
# Maximum number of statements in function / method body
max-statements=60
# Maximum number of parents for a class (see R0901).
max-parents=10
# Maximum number of attributes for a class (see R0902).
max-attributes=30
# Minimum number of public methods for a class (see R0903).
min-public-methods=0
# Maximum number of public methods for a class (see R0904).
max-public-methods=30

View File

@ -1,37 +0,0 @@
sudo: false
install:
- pip install tox
script:
- tox
language:
- python
matrix:
include:
- python: 2.7
env: TOXENV=coveralls DEPENDENCY_INJECTOR_DEBUG_MODE=1
install:
- pip install tox
- pip install cython
- make cythonize
- python: 2.7
env: TOXENV=pylint
- python: 2.7
env: TOXENV=flake8
- python: 2.7
env: TOXENV=pydocstyle
- python: 2.7
env: TOXENV=py27
- python: 3.4
env: TOXENV=py34
- python: 3.5
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
- python: 3.7
env: TOXENV=py37
sudo: required
dist: xenial
- python: pypy
env: TOXENV=pypy
notifications:
slack: ets-labs:g9OU0r5PXjA5ueeoQw01dVvV

View File

@ -1,8 +1,24 @@
Dependency Injector Contributors
================================
+ Roman Mogilatov (rmk135)
+ Roman Mogylatov (rmk135)
+ Konstantin vz'One Enchant (sirkonst)
+ Terrence Brannon (metaperl)
+ Stanislav Lobanov (asyncee)
+ James Lafa (jameslafa)
+ Vlad Ghita (vlad-ghita)
+ Jeroen Rietveld (jeroenrietveld)
+ Dmitry Kuzmin (xotonic)
+ supakeen (supakeen)
+ Bruno P. Kinoshita (kinow)
+ RobinsonMa (RobinsonMa)
+ Rüdiger Busche (JarnoRFB)
+ Dmitry Rassoshenko (rda-dev)
+ Fotis Koutoupas (kootoopas)
+ Shubhendra Singh Chauhan (withshubh)
+ sonthonaxrk (sonthonaxrk)
+ Ngo Thanh Loi (Leonn) (loingo95)
+ Thiago Hiromi (thiromi)
+ Felipe Rubio (krouw)
+ Anton Petrov (anton-petrov)
+ ZipFile (ZipFile)

View File

@ -1,4 +1,4 @@
Copyright (c) 2017, ETS Labs
Copyright (c) 2024, Roman Mogylatov
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,6 +1,7 @@
recursive-include src/dependency_injector *.py *.pyx *.pxd *.c
recursive-include src/dependency_injector *.py* *.c py.typed
recursive-include tests *.py
include README.rst
include CONTRIBUTORS.rst
include LICENSE.rst
include requirements.txt
include setup.py
include tox.ini

View File

@ -1,14 +1,6 @@
VERSION := $(shell python setup.py --version)
CYTHON_SRC := $(shell find src/dependency_injector -name '*.pyx')
CYTHON_DIRECTIVES =
ifdef DEPENDENCY_INJECTOR_DEBUG_MODE
CYTHON_DIRECTIVES += -Xprofile=True
CYTHON_DIRECTIVES += -Xlinetrace=True
endif
export COVERAGE_RCFILE := pyproject.toml
clean:
# Clean sources
@ -25,39 +17,45 @@ clean:
find examples -name '*.py[co]' -delete
find examples -name '__pycache__' -delete
cythonize:
# Compile Cython to C
cython -a $(CYTHON_DIRECTIVES) $(CYTHON_SRC)
build: clean
# Compile C extensions
python setup.py build_ext --inplace
# Move all Cython html reports
mkdir -p reports/cython/
find src -name '*.html' -exec mv {} reports/cython/ \;
build: clean cythonize
# Compile C extensions
python setup.py build_ext --inplace
docs-live:
sphinx-autobuild docs docs/_build/html
install: uninstall clean cythonize
install: uninstall clean build
pip install -ve .
uninstall:
- pip uninstall -y -q dependency-injector 2> /dev/null
test: build
test:
# Unit tests with coverage report
coverage erase
coverage run --rcfile=./.coveragerc -m unittest2 discover tests/unit
coverage report --rcfile=./.coveragerc
coverage html --rcfile=./.coveragerc
coverage run -m pytest
coverage report
coverage html
check:
# Static analysis
flake8 --max-complexity=10 src/dependency_injector/
flake8 --max-complexity=10 examples/
# Code style analysis
flake8 src/dependency_injector/
flake8 examples/
pydocstyle src/dependency_injector/
pydocstyle examples/
publish: cythonize
mypy tests/typing
test-publish: build
# Create distributions
python -m build --sdist
# Upload distributions to PyPI
twine upload --repository testpypi dist/dependency-injector-$(VERSION)*
publish:
# Merge release to master branch
git checkout master
git merge --no-ff release/$(VERSION) -m "Merge branch 'release/$(VERSION)' into master"
@ -65,5 +63,3 @@ publish: cythonize
# Create and upload tag
git tag -a $(VERSION) -m 'version $(VERSION)'
git push --tags
# Create and upload build
python setup.py sdist upload

View File

@ -1,407 +1,230 @@
====================================================================
Dependency Injector - Dependency injection microframework for Python
====================================================================
.. figure:: https://raw.githubusercontent.com/wiki/ets-labs/python-dependency-injector/img/logo.svg
:target: https://github.com/ets-labs/python-dependency-injector
*Dependency Injector* is a dependency injection microframework for Python.
It was designed to be unified, developer-friendly tool that helps to implement
dependency injection design pattern in formal, pretty, Pythonic way.
|
*Dependency Injector* framework key features are:
.. image:: https://img.shields.io/pypi/v/dependency_injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: Latest Version
.. image:: https://img.shields.io/pypi/l/dependency_injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: License
+ Easy, smart, pythonic style.
+ Obvious, clear structure.
+ Extensibility and flexibility.
+ High performance.
+ Memory efficiency.
+ Thread safety.
+ Documentation.
+ Semantic versioning.
.. image:: https://img.shields.io/pypi/pyversions/dependency_injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: Supported Python versions
.. image:: https://img.shields.io/pypi/implementation/dependency_injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: Supported Python implementations
*Dependency Injector* containers and providers are implemented as C extension
types using Cython.
.. image:: https://pepy.tech/badge/dependency-injector
:target: https://pepy.tech/project/dependency-injector
:alt: Downloads
Status
------
.. image:: https://pepy.tech/badge/dependency-injector/month
:target: https://pepy.tech/project/dependency-injector
:alt: Downloads
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
| *PyPi* | .. image:: https://img.shields.io/pypi/v/dependency_injector.svg |
| | :target: https://pypi.python.org/pypi/dependency_injector/ |
| | :alt: Latest Version |
| | .. image:: https://img.shields.io/pypi/l/dependency_injector.svg |
| | :target: https://pypi.python.org/pypi/dependency_injector/ |
| | :alt: License |
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
| *Python versions and implementations* | .. image:: https://img.shields.io/pypi/pyversions/dependency_injector.svg |
| | :target: https://pypi.python.org/pypi/dependency_injector/ |
| | :alt: Supported Python versions |
| | .. image:: https://img.shields.io/pypi/implementation/dependency_injector.svg |
| | :target: https://pypi.python.org/pypi/dependency_injector/ |
| | :alt: Supported Python implementations |
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
| *Builds and tests coverage* | .. image:: https://travis-ci.org/ets-labs/python-dependency-injector.svg?branch=master |
| | :target: https://travis-ci.org/ets-labs/python-dependency-injector |
| | :alt: Build Status |
| | .. image:: http://readthedocs.org/projects/python-dependency-injector/badge/?version=latest |
| | :target: http://python-dependency-injector.ets-labs.org/ |
| | :alt: Docs Status |
| | .. image:: https://coveralls.io/repos/github/ets-labs/python-dependency-injector/badge.svg?branch=master |
| | :target: https://coveralls.io/github/ets-labs/python-dependency-injector?branch=master |
| | :alt: Coverage Status |
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
| *Github* | .. image:: https://img.shields.io/github/watchers/ets-labs/python-dependency-injector.svg?style=social&label=Watch |
| | :target: https://github.com/ets-labs/python-dependency-injector |
| | :alt: Github watchers |
| | .. image:: https://img.shields.io/github/stars/ets-labs/python-dependency-injector.svg?style=social&label=Star |
| | :target: https://github.com/ets-labs/python-dependency-injector |
| | :alt: Github stargazers |
| | .. image:: https://img.shields.io/github/forks/ets-labs/python-dependency-injector.svg?style=social&label=Fork |
| | :target: https://github.com/ets-labs/python-dependency-injector |
| | :alt: Github forks |
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
.. image:: https://pepy.tech/badge/dependency-injector/week
:target: https://pepy.tech/project/dependency-injector
:alt: Downloads
Dependency injection
--------------------
.. image:: https://img.shields.io/pypi/wheel/dependency-injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: Wheel
`Dependency injection`_ is a software design pattern that implements
`Inversion of control`_ for resolving dependencies. Formally, if object **A**
depends on object **B**, object **A** must not create or import object **B**
directly. Instead of this object **A** must provide a way for *injecting*
object **B**. The responsibilities of objects creation and dependencies
injection are delegated to external code - the *dependency injector*.
.. image:: https://img.shields.io/github/actions/workflow/status/ets-labs/python-dependency-injector/tests-and-linters.yml?branch=master
:target: https://github.com/ets-labs/python-dependency-injector/actions
:alt: Build Status
Popular terminology of dependency injection pattern:
.. image:: https://coveralls.io/repos/github/ets-labs/python-dependency-injector/badge.svg?branch=master
:target: https://coveralls.io/github/ets-labs/python-dependency-injector?branch=master
:alt: Coverage Status
+ Object **A**, that is dependant on object **B**, is often called -
the *client*.
+ Object **B**, that is a dependency, is often called - the *service*.
+ External code that is responsible for creation of objects and injection
of dependencies is often called - the *dependency injector*.
What is ``Dependency Injector``?
================================
There are several ways of how *service* can be injected into the *client*:
``Dependency Injector`` is a dependency injection framework for Python.
+ by passing it as ``__init__`` argument (constructor / initializer injection)
+ by setting it as attribute's value (attribute injection)
+ by passing it as method's argument (method injection)
It helps implement the dependency injection principle.
Dependency injection pattern has few strict rules that should be followed:
Key features of the ``Dependency Injector``:
+ The *client* delegates to the *dependency injector* the responsibility
of injecting its dependencies - the *service(s)*.
+ The *client* doesn't know how to create the *service*, it knows only
interface of the *service*. The *service* doesn't know that it is used by
the *client*.
+ The *dependency injector* knows how to create the *client* and
the *service*, it also knows that the *client* depends on the *service*,
and knows how to inject the *service* into the *client*.
+ The *client* and the *service* know nothing about the *dependency injector*.
Dependency injection pattern provides the following advantages:
+ Control on application structure.
+ Decreased coupling between application components.
+ Increased code reusability.
+ Increased testability.
+ Increased maintainability.
+ Reconfiguration of system without rebuilding.
Example of dependency injection
-------------------------------
Let's go through next example:
.. image:: https://raw.githubusercontent.com/wiki/ets-labs/python-dependency-injector/img/engines_cars/diagram.png
:width: 100%
:align: center
Listing of ``example.engines`` module:
- **Providers**. Provides ``Factory``, ``Singleton``, ``Callable``, ``Coroutine``, ``Object``,
``List``, ``Dict``, ``Configuration``, ``Resource``, ``Dependency``, and ``Selector`` providers
that help assemble your objects.
See `Providers <https://python-dependency-injector.ets-labs.org/providers/index.html>`_.
- **Overriding**. Can override any provider by another provider on the fly. This helps in testing
and configuring dev/stage environment to replace API clients with stubs etc. See
`Provider overriding <https://python-dependency-injector.ets-labs.org/providers/overriding.html>`_.
- **Configuration**. Reads configuration from ``yaml``, ``ini``, and ``json`` files, ``pydantic`` settings,
environment variables, and dictionaries.
See `Configuration provider <https://python-dependency-injector.ets-labs.org/providers/configuration.html>`_.
- **Resources**. Helps with initialization and configuring of logging, event loop, thread
or process pool, etc. Can be used for per-function execution scope in tandem with wiring.
See `Resource provider <https://python-dependency-injector.ets-labs.org/providers/resource.html>`_.
- **Containers**. Provides declarative and dynamic containers.
See `Containers <https://python-dependency-injector.ets-labs.org/containers/index.html>`_.
- **Wiring**. Injects dependencies into functions and methods. Helps integrate with
other frameworks: Django, Flask, Aiohttp, Sanic, FastAPI, etc.
See `Wiring <https://python-dependency-injector.ets-labs.org/wiring.html>`_.
- **Asynchronous**. Supports asynchronous injections.
See `Asynchronous injections <https://python-dependency-injector.ets-labs.org/providers/async.html>`_.
- **Typing**. Provides typing stubs, ``mypy``-friendly.
See `Typing and mypy <https://python-dependency-injector.ets-labs.org/providers/typing_mypy.html>`_.
- **Performance**. Fast. Written in ``Cython``.
- **Maturity**. Mature and production-ready. Well-tested, documented, and supported.
.. code-block:: python
"""Dependency injection example, engines module."""
from dependency_injector import containers, providers
from dependency_injector.wiring import Provide, inject
class Engine(object):
"""Example engine base class.
class Container(containers.DeclarativeContainer):
Engine is a heart of every car. Engine is a very common term and could be
implemented in very different ways.
"""
config = providers.Configuration()
api_client = providers.Singleton(
ApiClient,
api_key=config.api_key,
timeout=config.timeout,
)
class GasolineEngine(Engine):
"""Gasoline engine."""
service = providers.Factory(
Service,
api_client=api_client,
)
class DieselEngine(Engine):
"""Diesel engine."""
@inject
def main(service: Service = Provide[Container.service]) -> None:
...
class ElectroEngine(Engine):
"""Electro engine."""
if __name__ == "__main__":
container = Container()
container.config.api_key.from_env("API_KEY", required=True)
container.config.timeout.from_env("TIMEOUT", as_=int, default=5)
container.wire(modules=[__name__])
Listing of ``example.cars`` module:
main() # <-- dependency is injected automatically
.. code-block:: python
with container.api_client.override(mock.Mock()):
main() # <-- overridden dependency is injected automatically
"""Dependency injection example, cars module."""
When you call the ``main()`` function the ``Service`` dependency is assembled and injected automatically.
When you do testing, you call the ``container.api_client.override()`` method to replace the real API
client with a mock. When you call ``main()``, the mock is injected.
class Car(object):
"""Example car."""
You can override any provider with another provider.
def __init__(self, engine):
"""Initializer."""
self._engine = engine # Engine is injected
It also helps you in a re-configuring project for different environments: replace an API client
with a stub on the dev or stage.
Next example demonstrates creation of several cars with different engines:
With the ``Dependency Injector``, object assembling is consolidated in a container. Dependency injections are defined explicitly.
This makes it easier to understand and change how an application works.
.. code-block:: python
.. figure:: https://raw.githubusercontent.com/wiki/ets-labs/python-dependency-injector/img/di-readme.svg
:target: https://github.com/ets-labs/python-dependency-injector
"""Dependency injection example, Cars & Engines."""
import example.cars
import example.engines
if __name__ == '__main__':
gasoline_car = example.cars.Car(example.engines.GasolineEngine())
diesel_car = example.cars.Car(example.engines.DieselEngine())
electro_car = example.cars.Car(example.engines.ElectroEngine())
While previous example demonstrates advantages of dependency injection, there
is a disadvantage demonstration as well - creation of car requires additional
code for specification of dependencies. Nevertheless, this disadvantage could
be easily avoided by using a dependency injection framework for creation of
inversion of control container (IoC container).
Example of creation of several inversion of control containers (IoC containers)
using *Dependency Injector*:
.. code-block:: python
"""Dependency injection example, Cars & Engines IoC containers."""
import example.cars
import example.engines
import dependency_injector.containers as containers
import dependency_injector.providers as providers
class Engines(containers.DeclarativeContainer):
"""IoC container of engine providers."""
gasoline = providers.Factory(example.engines.GasolineEngine)
diesel = providers.Factory(example.engines.DieselEngine)
electro = providers.Factory(example.engines.ElectroEngine)
class Cars(containers.DeclarativeContainer):
"""IoC container of car providers."""
gasoline = providers.Factory(example.cars.Car,
engine=Engines.gasoline)
diesel = providers.Factory(example.cars.Car,
engine=Engines.diesel)
electro = providers.Factory(example.cars.Car,
engine=Engines.electro)
if __name__ == '__main__':
gasoline_car = Cars.gasoline()
diesel_car = Cars.diesel()
electro_car = Cars.electro()
Dependency Injector structure
-----------------------------
Dependency Injector is a microframework and has a very simple structure.
There are 2 main entities: providers & containers.
.. image:: https://raw.githubusercontent.com/wiki/ets-labs/python-dependency-injector/img/internals.png
:width: 100%
:align: center
Providers
~~~~~~~~~
Providers are strategies of accessing objects. They define how particular
objects are provided.
- **Provider** - base provider class.
- **Callable** - provider that calls wrapped callable on every call. Supports
positional & keyword argument injections.
- **Factory** - provider that creates new instance of specified class on every
call. Supports positional & keyword argument injections, as well as
attribute injections.
- **Singleton** - provider that creates new instance of specified class on first
call and returns same instance on every next call. Supports positional &
keyword argument injections, as well as attribute injections.
- **Object** - provider that returns provided instance "as is".
- **ExternalDependency** - provider that can be useful for development of
self-sufficient libraries / modules / applications that has required
external dependencies.
- **Configuration** - provider that helps with implementing late static binding
of configuration options - use first, define later.
Containers
~~~~~~~~~~
Containers are collections of providers. Main purpose of containers is to
group providers.
- **DeclarativeContainer** - is inversion of control container that could be
defined in declarative manner. It should cover most of the cases when list
of providers that would be included in container is deterministic
(container will not change its structure in runtime).
- **DynamicContainer** - is an inversion of control container with dynamic
structure. It should cover most of the cases when list of providers that
would be included in container is non-deterministic and depends on
application's flow or its configuration (container's structure could be
determined just after application will be started and will do some initial
work, like parsing list of container providers from the configuration).
Dependency Injector in action
-----------------------------
Brief example below is a simplified version of inversion of control
container from one of the real-life applications. This example demonstrates
usage of *Dependency Injector* inversion of control container & providers
for specifying all application components and their dependencies between
each other in one module. Besides other listed above advantages, it gives a
great opportunity to control & manage application's structure in one place.
.. code-block:: python
"""Example of dependency injection in Python."""
import logging
import sqlite3
import boto3
from dependency_injector import containers, providers
from example import services, main
class IocContainer(containers.DeclarativeContainer):
"""Application IoC container."""
config = providers.Configuration('config')
logger = providers.Singleton(logging.Logger, name='example')
# Gateways
database_client = providers.Singleton(sqlite3.connect, config.database.dsn)
s3_client = providers.Singleton(
boto3.client, 's3',
aws_access_key_id=config.aws.access_key_id,
aws_secret_access_key=config.aws.secret_access_key,
)
# Services
users_service = providers.Factory(
services.UsersService,
db=database_client,
logger=logger,
)
auth_service = providers.Factory(
services.AuthService,
token_ttl=config.auth.token_ttl,
db=database_client,
logger=logger,
)
photos_service = providers.Factory(
services.PhotosService,
db=database_client,
s3=s3_client,
logger=logger,
)
# Misc
main = providers.Callable(
main.main,
users_service=users_service,
auth_service=auth_service,
photos_service=photos_service,
)
Next example demonstrates run of example application defined above:
.. code-block:: python
"""Run example of dependency injection in Python."""
import sys
import logging
from container import IocContainer
if __name__ == '__main__':
# Configure container:
container = IocContainer(
config={
'database': {
'dsn': ':memory:',
},
'aws': {
'access_key_id': 'KEY',
'secret_access_key': 'SECRET',
},
'auth': {
'token_ttl': 3600,
},
}
)
container.logger().addHandler(logging.StreamHandler(sys.stdout))
# Run application:
container.main(*sys.argv[1:])
You can get more *Dependency Injector* examples in ``/examples`` directory on
GitHub:
https://github.com/ets-labs/python-dependency-injector
Visit the docs to know more about the
`Dependency injection and inversion of control in Python <https://python-dependency-injector.ets-labs.org/introduction/di_in_python.html>`_.
Installation
------------
*Dependency Injector* library is available on `PyPi`_::
The package is available on the `PyPi`_::
pip install dependency_injector
pip install dependency-injector
Documentation
-------------
*Dependency Injector* documentation is hosted on ReadTheDocs:
The documentation is available `here <https://python-dependency-injector.ets-labs.org/>`_.
- `User's guide`_
- `API docs`_
Examples
--------
Feedback & Support
------------------
Choose one of the following:
Feel free to post questions, bugs, feature requests, proposals etc. on
*Dependency Injector* GitHub Issues:
- `Application example (single container) <https://python-dependency-injector.ets-labs.org/examples/application-single-container.html>`_
- `Application example (multiple containers) <https://python-dependency-injector.ets-labs.org/examples/application-multiple-containers.html>`_
- `Decoupled packages example (multiple containers) <https://python-dependency-injector.ets-labs.org/examples/decoupled-packages.html>`_
- `Boto3 example <https://python-dependency-injector.ets-labs.org/examples/boto3.html>`_
- `Django example <https://python-dependency-injector.ets-labs.org/examples/django.html>`_
- `Flask example <https://python-dependency-injector.ets-labs.org/examples/flask.html>`_
- `Aiohttp example <https://python-dependency-injector.ets-labs.org/examples/aiohttp.html>`_
- `Sanic example <https://python-dependency-injector.ets-labs.org/examples/sanic.html>`_
- `FastAPI example <https://python-dependency-injector.ets-labs.org/examples/fastapi.html>`_
- `FastAPI + Redis example <https://python-dependency-injector.ets-labs.org/examples/fastapi-redis.html>`_
- `FastAPI + SQLAlchemy example <https://python-dependency-injector.ets-labs.org/examples/fastapi-sqlalchemy.html>`_
https://github.com/ets-labs/python-dependency-injector/issues
Tutorials
---------
Your feedback is quite important!
Choose one of the following:
- `Flask web application tutorial <https://python-dependency-injector.ets-labs.org/tutorials/flask.html>`_
- `Aiohttp REST API tutorial <https://python-dependency-injector.ets-labs.org/tutorials/aiohttp.html>`_
- `Asyncio monitoring daemon tutorial <https://python-dependency-injector.ets-labs.org/tutorials/asyncio-daemon.html>`_
- `CLI application tutorial <https://python-dependency-injector.ets-labs.org/tutorials/cli.html>`_
.. _Dependency injection: http://en.wikipedia.org/wiki/Dependency_injection
.. _Inversion of control: https://en.wikipedia.org/wiki/Inversion_of_control
.. _PyPi: https://pypi.python.org/pypi/dependency_injector
.. _User's guide: http://python-dependency-injector.ets-labs.org/
.. _API docs: http://python-dependency-injector.ets-labs.org/api/
Concept
-------
The framework stands on the `PEP20 (The Zen of Python) <https://www.python.org/dev/peps/pep-0020/>`_ principle:
.. code-block:: bash
Explicit is better than implicit
You need to specify how to assemble and where to inject the dependencies explicitly.
The power of the framework is in its simplicity.
``Dependency Injector`` is a simple tool for the powerful concept.
Frequently asked questions
--------------------------
What is dependency injection?
- dependency injection is a principle that decreases coupling and increases cohesion
Why should I do the dependency injection?
- your code becomes more flexible, testable, and clear 😎
How do I start applying the dependency injection?
- you start writing the code following the dependency injection principle
- you register all of your application components and their dependencies in the container
- when you need a component, you specify where to inject it or get it from the container
What price do I pay and what do I get?
- you need to explicitly specify the dependencies
- it will be extra work in the beginning
- it will payoff as project grows
Have a question?
- Open a `Github Issue <https://github.com/ets-labs/python-dependency-injector/issues>`_
Found a bug?
- Open a `Github Issue <https://github.com/ets-labs/python-dependency-injector/issues>`_
Want to help?
- |star| Star the ``Dependency Injector`` on the `Github <https://github.com/ets-labs/python-dependency-injector/>`_
- |new| Start a new project with the ``Dependency Injector``
- |tell| Tell your friend about the ``Dependency Injector``
Want to contribute?
- |fork| Fork the project
- |pull| Open a pull request to the ``develop`` branch
.. _PyPi: https://pypi.org/project/dependency-injector/
.. |star| unicode:: U+2B50 U+FE0F .. star sign1
.. |new| unicode:: U+1F195 .. new sign
.. |tell| unicode:: U+1F4AC .. tell sign
.. |fork| unicode:: U+1F500 .. fork sign
.. |pull| unicode:: U+2B05 U+FE0F .. pull sign

9
docs/_static/custom.css vendored Normal file
View File

@ -0,0 +1,9 @@
.no-border {
border: 0 !important;
box-shadow: none !important;
-webkit-box-shadow: none !important;
}
.no-border td {
border: 0px !important;
padding: 0px 10px 0px 0px !important;
}

View File

@ -1,10 +0,0 @@
var disqus_shortname;
var disqus_identifier;
(function() {{
var disqus_thread = $("#disqus_thread");
disqus_shortname = disqus_thread.data('disqus-shortname');
disqus_identifier = disqus_thread.data('disqus-identifier');
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}})();

1
docs/_static/logo.svg vendored Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -1,3 +0,0 @@
.rst-content .highlight>pre, .rst-content .linenodiv>pre {
line-height: normal;
}

1
docs/_static/sponsor.html vendored Normal file
View File

@ -0,0 +1 @@
<iframe src="https://github.com/sponsors/rmk135/button" title="Sponsor Dependency Injector" height="32" width="114" style="border: 0; border-radius: 6px;"></iframe>

View File

@ -0,0 +1,9 @@
dependency_injector.ext.starlette
=================================
.. automodule:: dependency_injector.ext.starlette
:members:
:inherited-members:
:show-inheritance:
.. disqus::

View File

@ -1,9 +1,9 @@
``dependency_injector.containers``
----------------------------------
dependency_injector.containers
==============================
.. automodule:: dependency_injector.containers
:members:
:special-members:
:inherited-members:
:show-inheritance:
.. disqus::

View File

@ -1,5 +1,5 @@
``dependency_injector.errors``
------------------------------
dependency_injector.errors
==========================
.. automodule:: dependency_injector.errors
:members:

View File

@ -2,9 +2,11 @@ API Documentation
=================
.. toctree::
:maxdepth: 2
:maxdepth: 2
top_level
providers
containers
errors
top-level
providers
containers
wiring
errors
asgi-lifespan

View File

@ -1,5 +1,5 @@
``dependency_injector.providers``
---------------------------------
dependency_injector.providers
=============================
.. automodule:: dependency_injector.providers
:members:

View File

@ -1,5 +1,5 @@
``dependency_injector``
-----------------------
dependency_injector
===================
.. automodule:: dependency_injector
:members: __version__

7
docs/api/wiring.rst Normal file
View File

@ -0,0 +1,7 @@
dependency_injector.wiring
=============================
.. automodule:: dependency_injector.wiring
:members:
.. disqus::

View File

@ -15,50 +15,54 @@
import os
import re
import sys
import alabaster
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
#needs_sphinx = "1.0"
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinxcontrib.disqus']
extensions = [
"alabaster",
"sphinx.ext.autodoc",
"sphinx_disqus.disqus",
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# source_suffix = [".rst", ".md"]
source_suffix = ".rst"
# The encoding of source files.
#source_encoding = 'utf-8-sig'
#source_encoding = "utf-8-sig"
# The master toctree document.
master_doc = 'index'
master_doc = "index"
# General information about the project.
project = u'Dependency Injector'
copyright = u'2017, ETS Labs'
author = u'ETS Labs'
project = "Dependency Injector"
copyright = "2024, Roman Mogylatov"
author = "Roman Mogylatov"
# The version info for the project you're documenting, acts as replacement for
# The version info for the project you"re documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
# Getting version:
with open('../src/dependency_injector/__init__.py') as init_file:
version = re.search('__version__ = \'(.*?)\'', init_file.read()).group(1)
with open("../src/dependency_injector/__init__.py") as init_file:
version = re.search("__version__ = \"(.*?)\"", init_file.read()).group(1)
# The full version, including alpha/beta/rc tags.
release = version
@ -68,23 +72,23 @@ release = version
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
#today = ""
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
#today_fmt = "%B %d, %Y"
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
exclude_patterns = ["_build"]
# The reST default role (used for this markup: `text`) to use for all
# documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
# If true, "()" will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
@ -96,7 +100,7 @@ exclude_patterns = ['_build']
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
@ -112,7 +116,8 @@ todo_include_todos = False
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
# html_theme = "sphinx_rtd_theme"
html_theme = "alabaster"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@ -120,7 +125,7 @@ html_theme = 'sphinx_rtd_theme'
# html_context = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = ['_themes']
html_theme_path = [alabaster.get_path()]
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
@ -136,21 +141,24 @@ html_theme = 'sphinx_rtd_theme'
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
html_favicon = "favicon.ico"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
html_css_files = [
"custom.css",
]
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
#html_extra_path = []
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# If not "", a "Last updated on:" timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
#html_last_updated_fmt = "%b %d, %Y"
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
@ -184,50 +192,50 @@ html_static_path = ['_static']
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
#html_use_opensearch = ""
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Language to be used for generating the HTML full-text search index.
# Sphinx supports the following languages:
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr'
#html_search_language = 'en'
# "da", "de", "en", "es", "fi", "fr", "hu", "it", "ja"
# "nl", "no", "pt", "ro", "ru", "sv", "tr"
#html_search_language = "en"
# A dictionary with options for the search language support, empty by default.
# Now only 'ja' uses this config value
#html_search_options = {'type': 'default'}
# Now only "ja" uses this config value
#html_search_options = {"type": "default"}
# The name of a javascript file (relative to the configuration directory) that
# implements a search results scorer. If empty, the default will be used.
#html_search_scorer = 'scorer.js'
#html_search_scorer = "scorer.js"
# Output file base name for HTML help builder.
htmlhelp_basename = 'dependency_injectordoc'
htmlhelp_basename = "dependency_injectordoc"
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The paper size ("letterpaper" or "a4paper").
#"papersize": "letterpaper",
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# The font size ("10pt", "11pt" or "12pt").
#"pointsize": "10pt",
# Additional stuff for the LaTeX preamble.
#'preamble': '',
#"preamble": "",
# Latex figure (float) alignment
#'figure_align': 'htbp',
#"figure_align": "htbp",
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'dependency_injector.tex', u'Dependency Injector Documentation',
u'ETS Labs', 'manual'),
(master_doc, "dependency_injector.tex", u"Dependency Injector Documentation",
u"Roman Mogylatov", "manual"),
]
# The name of an image file (relative to this directory) to place at the top of
@ -256,7 +264,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'Dependency Injector', u'Dependency Injector Documentation',
(master_doc, "Dependency Injector", u"Dependency Injector Documentation",
[author], 1)
]
@ -270,9 +278,9 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Dependency Injector', u'Dependency Injector Documentation',
author, 'Dependency Injector', 'Dependency injection microframework for Python',
'Miscellaneous'),
(master_doc, "Dependency Injector", u"Dependency Injector Documentation",
author, "Dependency Injector", "Dependency injection microframework for Python",
"Miscellaneous"),
]
# Documents to append as an appendix to all manuals.
@ -281,16 +289,25 @@ texinfo_documents = [
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# How to display URL addresses: "footnote", "no", or "inline".
#texinfo_show_urls = "footnote"
# If true, do not generate a @detailmenu in the "Top" node's menu.
# If true, do not generate a @detailmenu in the "Top" node"s menu.
#texinfo_no_detailmenu = False
autodoc_member_order = 'bysource'
autodoc_member_order = "bysource"
disqus_shortname = 'python-dependency-injector'
disqus_shortname = "python-dependency-injector"
def setup(app):
app.add_stylesheet('sphinx_rtd_theme-hotfix.css')
html_theme_options = {
"github_user": "ets-labs",
"github_repo": "python-dependency-injector",
"github_type": "star",
"github_button": True,
"github_banner": True,
"logo": "logo.svg",
"description": "Dependency injection framework for Python by Roman Mogylatov",
"code_font_size": "10pt",
"analytics_id": "UA-67012059-1",
"donate_url": "https://github.com/sponsors/rmk135",
}

View File

@ -0,0 +1,18 @@
.. _check-container-dependencies:
Check container dependencies
----------------------------
To check container dependencies use method ``.check_dependencies()``.
.. literalinclude:: ../../examples/containers/check_dependencies.py
:language: python
:lines: 3-
:emphasize-lines: 12
Method ``.check_dependencies()`` raises an error if container has any undefined dependencies.
If all dependencies are provided or have defaults, no error is raised.
See also: :ref:`dependency-provider`.
.. disqus::

View File

@ -0,0 +1,23 @@
Container copying
-----------------
You can create declarative container copies using ``@containers.copy()`` decorator.
.. literalinclude:: ../../examples/containers/declarative_copy_decorator1.py
:language: python
:lines: 3-
:emphasize-lines: 18-22
Decorator ``@containers.copy()`` copies providers from source container to destination container.
Destination container provider will replace source provider, if names match.
Decorator ``@containers.copy()`` helps you when you create derived declarative containers
from the base one. Base container often keeps default dependencies while derived containers define
overriding providers. Without ``@containers.copy()`` decorator, overridden providers are available
in the derived container, but base class dependencies continue to be bound to the base class providers.
.. literalinclude:: ../../examples/containers/declarative_copy_decorator2.py
:language: python
:lines: 11-
.. disqus::

View File

@ -1,58 +1,72 @@
Declarative containers
----------------------
Declarative container
---------------------
.. currentmodule:: dependency_injector.containers
:py:class:`DeclarativeContainer` is inversion of control container that
could be defined in declarative manner. It should cover most of the cases
when list of providers that would be included in container is deterministic
(container will not change its structure in runtime).
:py:class:`DeclarativeContainer` is a class-based style of the providers definition.
Declarative containers have to extend base declarative container class -
:py:class:`dependency_injector.containers.DeclarativeContainer`.
Declarative container's providers have to be defined like container's class
attributes. Every provider in container has name. This name should follow
``some_provider`` convention, that is standard naming convention for
attribute names in Python.
.. note::
Declarative containers have several features that could be useful
for some kind of operations on container's providers, please visit API
documentation for getting full list of features -
:py:class:`dependency_injector.containers.DeclarativeContainer`.
Here is an simple example of defining declarative container with several
factories:
.. image:: /images/containers/declarative.png
:width: 85%
:align: center
You create the declarative container subclass, put the providers as attributes and create the
container instance.
.. literalinclude:: ../../examples/containers/declarative.py
:language: python
:linenos:
:lines: 3-
Example of declarative containers inheritance:
The declarative container providers should only be used when you have the container instance.
Working with the providers of the container on the class level will influence all further
instances.
.. image:: /images/containers/declarative_inheritance.png
:width: 100%
:align: center
The declarative container can not have any methods or any other attributes then providers.
The container class provides next attributes:
- ``providers`` - the dictionary of all the container providers
- ``cls_providers`` - the dictionary of the container providers of the current container
- ``inherited_providers`` - the dictionary of all the inherited container providers
.. literalinclude:: ../../examples/containers/declarative_inheritance.py
:language: python
:linenos:
:lines: 3-
Example of declarative containers's provider injections:
.. image:: /images/containers/declarative_injections.png
:width: 100%
:align: center
Injections in the declarative container are done the usual way:
.. literalinclude:: ../../examples/containers/declarative_injections.py
:language: python
:linenos:
:lines: 3-
You can override container providers while creating a container instance:
.. literalinclude:: ../../examples/containers/declarative_override_providers.py
:language: python
:lines: 3-
:emphasize-lines: 13
Alternatively, you can call ``container.override_providers()`` method when the container instance
already exists:
.. code-block:: python
:emphasize-lines: 3
container = Container()
container.override_providers(foo=mock.Mock(Foo), bar=mock.Mock(Bar))
assert isinstance(container.foo(), mock.Mock)
assert isinstance(container.bar(), mock.Mock)
You can also use ``container.override_providers()`` with a context manager to reset
provided overriding after the context is closed:
.. code-block:: python
:emphasize-lines: 3
container = Container()
with container.override_providers(foo=mock.Mock(Foo), bar=mock.Mock(Bar)):
assert isinstance(container.foo(), mock.Mock)
assert isinstance(container.bar(), mock.Mock)
assert isinstance(container.foo(), Foo)
assert isinstance(container.bar(), Bar)
.. disqus::

View File

@ -1,30 +1,25 @@
Dynamic containers
------------------
Dynamic container
-----------------
.. currentmodule:: dependency_injector.containers
:py:class:`DynamicContainer` is an inversion of control container with dynamic
structure. It should cover most of the cases when list of providers that
would be included in container is non-deterministic and depends on
application's flow or its configuration (container's structure could be
determined just after application will be started and will do some initial
work, like parsing list of container's providers from the configuration).
:py:class:`DynamicContainer` is a collection of the providers defined in the runtime.
While :py:class:`DeclarativeContainer` acts on class-level,
:py:class:`DynamicContainer` does the same on instance-level.
Here is an simple example of defining dynamic container with several factories:
You create the dynamic container instance and put the providers as attributes.
.. literalinclude:: ../../examples/containers/dynamic.py
:language: python
:linenos:
:lines: 3-
Next example demonstrates creation of dynamic container based on some
configuration:
The dynamic container is good for the case when your application structure depends on the
configuration file or some other source that you can reach only after application is already
running (database, api, etc).
In this example we use the configuration to fill in the dynamic container with the providers:
.. literalinclude:: ../../examples/containers/dynamic_runtime_creation.py
:language: python
:linenos:
:lines: 3-
.. disqus::

View File

@ -1,23 +1,20 @@
IoC Containers
==============
.. _containers:
Containers are collections of providers. Main purpose of containers is to group
providers.
Containers
==========
There are, actually, several popular cases of containers usage:
Containers are collections of the providers.
+ Keeping all providers in a single container.
+ Grouping of providers from the same architectural layer (for example,
There are several use cases how you can use containers:
+ Keeping all the providers in a single container (most common).
+ Grouping of the providers from the same architectural layer (for example,
``Services``, ``Models`` and ``Forms`` containers).
+ Grouping of providers from the same functional groups (for example,
container ``Users``, that contains all functional parts of ``Users``
component).
container ``Users``, that contains all functional parts of the ``users``
package).
Also, for both of these and some other cases, it might be useful to attach
some init / shutdown functionality or something else, that deals with group
of providers.
Containers package API docs - :py:mod:`dependency_injector.containers`.
Containers module API docs - :py:mod:`dependency_injector.containers`.
.. toctree::
:maxdepth: 2
@ -26,3 +23,7 @@ Containers package API docs - :py:mod:`dependency_injector.containers`.
dynamic
specialization
overriding
copying
reset_singletons
check_dependencies
traversal

View File

@ -1,43 +1,40 @@
Overriding of containers
------------------------
Container overriding
--------------------
.. currentmodule:: dependency_injector.containers
Containers can be overridden by other containers. This, actually, means that
all of the providers from overriding container will override providers with
the same names in overridden container.
The container can be overridden by the other container. All of the providers from the overriding
container will override the providers with the same names in the overridden container.
There are two ways to override :py:class:`DeclarativeContainer` with another
container:
- Use :py:meth:`DeclarativeContainer.override` method.
- Use :py:func:`override` class decorator.
Example of overriding container using :py:meth:`DeclarativeContainer.override`
method:
.. literalinclude:: ../../examples/containers/override_declarative.py
.. literalinclude:: ../../examples/containers/override.py
:language: python
:linenos:
:lines: 3-
Example of overriding container using :py:func:`override` decorator:
It helps in a testing. Also you can use it for configuring project for the different
environments: replace an API client with a stub on the dev or stage.
.. literalinclude:: ../../examples/containers/override_declarative_decorator.py
The container also has:
- ``container.overridden`` - tuple of all overriding containers.
- ``container.reset_last_overriding()`` - reset last overriding for each provider in the container.
- ``container.reset_override()`` - reset all overriding in the container.
:py:class:`DynamicContainer` has the same functionality.
Another possible way to override container providers on declarative level is
``@containers.override()`` decorator:
.. literalinclude:: ../../examples/containers/declarative_override_decorator.py
:language: python
:linenos:
:lines: 3-
:emphasize-lines: 12-16
Also there are several useful :py:class:`DeclarativeContainer` methods and
properties that help to work with container overridings:
- :py:attr:`DeclarativeContainer.overridden` - tuple of all overriding
containers.
- :py:meth:`DeclarativeContainer.reset_last_overriding()` - reset last
overriding provider for each container providers.
- :py:meth:`DeclarativeContainer.reset_override()` - reset all overridings
for each container providers.
:py:class:`DynamicContainer` has exactly the same functionality, except of
:py:func:`override` decorator.
Decorator ``@containers.override()`` takes a container for overriding as an argument.
This container providers will be overridden by the providers with the same names from
the decorated container.
It helps to change the behaviour of application by importing extension modules but not a code change.
Imported module can override providers in main container. While the code uses main container as
before, the overridden providers provide components defined in the extension module.
.. disqus::

View File

@ -0,0 +1,31 @@
.. _reset-container-singletons:
Reset container singletons
--------------------------
To reset all container singletons use method ``.reset_singletons()``.
.. literalinclude:: ../../examples/containers/reset_singletons.py
:language: python
:lines: 3-
:emphasize-lines: 16
Method ``.reset_singletons()`` also resets singletons in sub-containers: ``providers.Container`` and
``providers.DependenciesContainer.``
.. literalinclude:: ../../examples/containers/reset_singletons_subcontainers.py
:language: python
:lines: 3-
:emphasize-lines: 21
You can use ``.reset_singletons()`` method with a context manager. Singletons will be reset on
both entering and exiting a context.
.. literalinclude:: ../../examples/containers/reset_singletons_with.py
:language: python
:lines: 3-
:emphasize-lines: 14-15
See also: :ref:`singleton-provider`.
.. disqus::

View File

@ -1,27 +1,25 @@
Specialization of containers
----------------------------
Specialization of the container provider type
---------------------------------------------
.. currentmodule:: dependency_injector.containers
:py:class:`DeclarativeContainer` could be specialized for any kind of needs
via declaring its subclasses.
One of such `builtin` features is a limitation for providers type.
Next example shows usage of this feature with :py:class:`DeclarativeContainer`
in couple with feature of :py:class:`dependency_injector.providers.Factory`
for limitation of its provided type:
You can make a restriction of the :py:class:`DeclarativeContainer` provider type:
.. literalinclude:: ../../examples/containers/declarative_provider_type.py
:language: python
:linenos:
:lines: 3-
:emphasize-lines: 29-31
Limitation for providers type could be used with :py:class:`DynamicContainer`
as well:
The emphasized lines will cause an error because ``other_provider`` is not a subtype of the
``ServiceProvider``. This helps to control the content of the container.
The same works for the :py:class:`DynamicContainer`:
.. literalinclude:: ../../examples/containers/dynamic_provider_type.py
:language: python
:linenos:
:lines: 3-
:emphasize-lines: 23
The emphasized line will also cause an error.
.. disqus::

View File

@ -0,0 +1,33 @@
Container providers traversal
-----------------------------
To traverse container providers use method ``.traverse()``.
.. literalinclude:: ../../examples/containers/traverse.py
:language: python
:lines: 3-
:emphasize-lines: 38
Method ``.traverse()`` returns a generator. Traversal generator visits all container providers.
This includes nested providers even if they are not present on the root level of the container.
Traversal generator guarantees that each container provider will be visited only once.
It can traverse cyclic provider graphs.
Traversal generator does not guarantee traversal order.
You can use ``types=[...]`` argument to filter providers. Traversal generator will only return
providers matching specified types.
.. code-block:: python
:emphasize-lines: 3
container = Container()
for provider in container.traverse(types=[providers.Resource]):
print(provider)
# <dependency_injector.providers.Resource(<function init_database at 0x10bd2cb80>) at 0x10d346b40>
# <dependency_injector.providers.Resource(<function init_cache at 0x10be373a0>) at 0x10d346bc0>
.. disqus::

View File

@ -0,0 +1,68 @@
Chained Factories pattern
=========================
This example demonstrates "Chained Factories" pattern.
The idea of the pattern is in wrapping ``Factory`` into another ``Factory`` that adds
additional arguments.
.. code-block:: python
base_factory = providers.Factory(
SomeClass,
base_argument=1,
)
concrete_factory = providers.Factory(
base_factory,
extra_argument=2,
)
if __name__ == "__main__":
instance = concrete_factory()
# Same as: # instance = SomeClass(base_argument=1, extra_argument=2)
Sample code
-----------
Listing of the pattern example:
.. literalinclude:: ../../examples/miniapps/factory-patterns/chained_factories.py
:language: python
Arguments priority
------------------
Passing of the arguments works the same way like for any other :ref:`factory-provider`.
.. code-block:: python
# 1. Keyword arguments of upper level factory are added to lower level factory
chained_dict_factory = providers.Factory(
providers.Factory(dict, arg1=1),
arg2=2,
)
print(chained_dict_factory()) # prints: {"arg1": 1, "arg2": 2}
# 2. Keyword arguments of upper level factory have priority
chained_dict_factory = providers.Factory(
providers.Factory(dict, arg1=1),
arg1=2,
)
print(chained_dict_factory()) # prints: {"arg1": 2}
# 3. Keyword arguments provided from context have the most priority
chained_dict_factory = providers.Factory(
providers.Factory(dict, arg1=1),
arg1=2,
)
print(chained_dict_factory(arg1=3)) # prints: {"arg1": 3}
Credits
-------
The "Chained Factories" pattern was suggested by the ``Dependency Injector`` users.
.. disqus::

View File

@ -0,0 +1,74 @@
Factory of Factories pattern
============================
This example demonstrates "Factory of Factories" pattern.
The idea of the pattern is in creating a ``Factory`` that creates another ``Factory`` and adds
additional arguments.
.. code-block:: python
base_factory = providers.Factory(
providers.Factory
SomeClass,
base_argument=1,
)
concrete_factory = providers.Factory(
OtherClass,
instance=base_factory(extra_argument=1),
)
if __name__ == "__main__":
instance = concrete_factory()
# Same as: # instance = SomeClass(base_argument=1, extra_argument=2)
Sample code
-----------
Listing of the pattern example:
.. literalinclude:: ../../examples/miniapps/factory-patterns/factory_of_factories.py
:language: python
Arguments priority
------------------
Passing of the arguments works the same way like for any other :ref:`factory-provider`.
.. code-block:: python
# 1. Keyword arguments of upper level factory are added to lower level factory
factory_of_dict_factories = providers.Factory(
providers.Factory,
dict,
arg1=1,
)
dict_factory = factory_of_dict_factories(arg2=2)
print(dict_factory()) # prints: {"arg1": 1, "arg2": 2}
# 2. Keyword arguments of upper level factory have priority
factory_of_dict_factories = providers.Factory(
providers.Factory,
dict,
arg1=1,
)
dict_factory = factory_of_dict_factories(arg1=2)
print(dict_factory()) # prints: {"arg1": 2}
# 3. Keyword arguments provided from context have the most priority
factory_of_dict_factories = providers.Factory(
providers.Factory,
dict,
arg1=1,
)
dict_factory = factory_of_dict_factories(arg1=2)
print(dict_factory(arg1=3)) # prints: {"arg1": 3}
Credits
-------
The "Factory of Factories" pattern was suggested by the ``Dependency Injector`` users.
.. disqus::

View File

@ -0,0 +1,17 @@
Other examples
==============
.. meta::
:keywords: Python,Dependency Injection,Inversion of Control,Container,Example,Application,
Framework
:description: This sections contains assorted Dependency Injector examples.
This sections contains assorted ``Dependency Injector`` examples.
.. toctree::
:maxdepth: 2
use-cases
password-hashing
chained-factories
factory-of-factories

View File

@ -0,0 +1,30 @@
Password hashing example
========================
.. meta::
:keywords: Python,Dependency Injection,Inversion of Control,Container,Example,Application,
Framework,Callable
:description: This example demonstrates a usage of the Callable provider.
This example demonstrates an injection of the ``Callable`` provider.
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/password-hashing>`_.
Sample code
-----------
Listing of the pattern example:
.. literalinclude:: ../../examples/miniapps/password-hashing/example.py
:language: python
Run the example
---------------
Instructions for running:
.. code-block:: bash
python example.py
.. disqus::

View File

@ -0,0 +1,74 @@
Use cases example
=================
.. meta::
:keywords: Python,Dependency Injection,Inversion of Control,Container,Example,Application,
Framework,DependenciesContainer
:description: This example demonstrates a usage of the DependenciesContainer provider.
This example demonstrates a usage of the ``DependenciesContainer`` provider.
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/decoupled-packages>`_.
Application structure
---------------------
Example application has next structure:
.. code-block:: bash
./
└── example/
├── __init__.py
├── __main__.py
├── adapters.py
├── containers.py
└── usecases.py
Containers
----------
Listing of the ``example/containers.py``:
.. literalinclude:: ../../examples/miniapps/use-cases/example/containers.py
:language: python
Main module
-----------
Listing of the ``example/__main__.py``:
.. literalinclude:: ../../examples/miniapps/use-cases/example/__main__.py
:language: python
Run the application
-------------------
Instructions for running in the "test" mode:
.. code-block:: bash
python run.py test example@example.com
Instructions for running in the "prod" mode:
.. code-block:: bash
python run.py prod example@example.com
Adapters and use cases
----------------------
Listing of the ``example/adapters.py``:
.. literalinclude:: ../../examples/miniapps/use-cases/example/adapters.py
:language: python
Listing of the ``example/usecases.py``:
.. literalinclude:: ../../examples/miniapps/use-cases/example/usecases.py
:language: python
.. disqus::

83
docs/examples/aiohttp.rst Normal file
View File

@ -0,0 +1,83 @@
.. _aiohttp-example:
Aiohttp example
===============
.. meta::
:keywords: Python,Dependency Injection,Aiohttp,Example
:description: This example demonstrates a usage of the Aiohttp and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `Aiohttp <https://docs.aiohttp.org/>`_.
The example application is a REST API that searches for funny GIFs on the `Giphy <https://giphy.com/>`_.
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/aiohttp>`_.
:ref:`aiohttp-tutorial` demonstrates how to build this application step-by-step.
Application structure
---------------------
Application has next structure:
.. code-block:: bash
./
├── giphynavigator/
│ ├── __init__.py
│ ├── application.py
│ ├── containers.py
│ ├── giphy.py
│ ├── handlers.py
│ ├── services.py
│ └── tests.py
├── config.yml
└── requirements.txt
Container
---------
Declarative container is defined in ``giphynavigator/containers.py``:
.. literalinclude:: ../../examples/miniapps/aiohttp/giphynavigator/containers.py
:language: python
Handlers
--------
Handler has dependencies on search service and some config options. The dependencies are injected
using :ref:`wiring` feature.
Listing of ``giphynavigator/handlers.py``:
.. literalinclude:: ../../examples/miniapps/aiohttp/giphynavigator/handlers.py
:language: python
Application factory
-------------------
Application factory creates container, wires it with the ``handlers`` module, creates
``Aiohttp`` app and setup routes.
Listing of ``giphynavigator/application.py``:
.. literalinclude:: ../../examples/miniapps/aiohttp/giphynavigator/application.py
:language: python
Tests
-----
Tests use :ref:`provider-overriding` feature to replace giphy client with a mock ``giphynavigator/tests.py``:
.. literalinclude:: ../../examples/miniapps/aiohttp/giphynavigator/tests.py
:language: python
:emphasize-lines: 32,59,73
Sources
-------
Explore the sources on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/aiohttp>`_.
.. include:: ../sponsor.rst
.. disqus::

View File

@ -0,0 +1,89 @@
.. _application-multiple-containers:
Application example (multiple containers)
=========================================
.. meta::
:keywords: Python,Dependency Injection,Inversion of Control,Container,Example,Application,
Framework,AWS,boto3,client
:description: This example shows how you can create an application using multiple declarative
containers. We build an example Python micro application following the dependency
injection principle. It consists from several services with a domain logic that
have dependencies on database & AWS S3.
This example shows how you can create an application using multiple declarative containers. Using
multiple declarative containers is a good choice for a large application. For
building a moderate or a small size application refer to :ref:`application-single-container`.
We build an example micro application following the dependency injection principle. It consists
of several services with a domain logic. The services have dependencies on database & AWS S3.
.. image:: images/application.png
:width: 100%
:align: center
Start from the scratch or jump to the section:
.. contents::
:local:
:backlinks: none
You can find the source code and instructions for running on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/application-multiple-containers>`_.
Application structure
---------------------
Application consists of an ``example`` package, a configuration file and a ``requirements.txt``
file.
.. code-block:: bash
./
├── example/
│ ├── __init__.py
│ ├── __main__.py
│ ├── containers.py
│ └── services.py
├── config.yml
└── requirements.txt
Containers
----------
Listing of the ``example/containers.py``:
.. literalinclude:: ../../examples/miniapps/application-multiple-containers/example/containers.py
:language: python
Main module
-----------
Listing of the ``example/__main__.py``:
.. literalinclude:: ../../examples/miniapps/application-multiple-containers/example/__main__.py
:language: python
Services
--------
Listing of the ``example/services.py``:
.. literalinclude:: ../../examples/miniapps/application-multiple-containers/example/services.py
:language: python
Configuration
-------------
Listing of the ``config.yml``:
.. literalinclude:: ../../examples/miniapps/application-multiple-containers/config.yml
:language: yaml
Run the application
-------------------
You can find the source code and instructions for running on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/application-multiple-containers>`_.
.. include:: ../sponsor.rst
.. disqus::

View File

@ -0,0 +1,95 @@
.. _application-single-container:
Application example (single container)
======================================
.. meta::
:keywords: Python,Dependency Injection,Inversion of Control,Container,Example,Application,
Framework,AWS,boto3,client
:description: This example shows how you can create an application using a single declarative
container. We build an example Python micro application following the dependency
injection principle. It consists from several services with a domain logic that
have dependencies on database & AWS S3.
This example shows how you can create an application using a single declarative container. Using
a single declarative container is a good choice for small or moderate size application. For
building a large application refer to :ref:`application-multiple-containers`.
We build an example micro application following the dependency injection principle. It consists
of several services with a domain logic. The services have dependencies on database & AWS S3.
.. image:: images/application.png
:width: 100%
:align: center
Start from the scratch or jump to the section:
.. contents::
:local:
:backlinks: none
You can find the source code and instructions for running on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/application-single-container>`_.
Application structure
---------------------
Application consists of an ``example`` package, several configuration files and a
``requirements.txt`` file.
.. code-block:: bash
./
├── example/
│ ├── __init__.py
│ ├── __main__.py
│ ├── containers.py
│ └── services.py
├── config.ini
├── logging.ini
└── requirements.txt
Container
---------
Listing of the ``example/containers.py``:
.. literalinclude:: ../../examples/miniapps/application-single-container/example/containers.py
:language: python
Main module
-----------
Listing of the ``example/__main__.py``:
.. literalinclude:: ../../examples/miniapps/application-single-container/example/__main__.py
:language: python
Services
--------
Listing of the ``example/services.py``:
.. literalinclude:: ../../examples/miniapps/application-single-container/example/services.py
:language: python
Configuration
-------------
Listing of the ``config.ini``:
.. literalinclude:: ../../examples/miniapps/application-single-container/config.ini
:language: ini
Listing of the ``logging.ini``:
.. literalinclude:: ../../examples/miniapps/application-single-container/logging.ini
:language: ini
Run the application
-------------------
You can find the source code and instructions for running on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/application-single-container>`_.
.. include:: ../sponsor.rst
.. disqus::

22
docs/examples/boto3.rst Normal file
View File

@ -0,0 +1,22 @@
.. _boto3-example:
Boto3 example
=============
.. meta::
:keywords: Python,Dependency Injection,Boto3,AWS,Amazon Web Services,S3,SQS,Rout53,EC2,Lambda,Example
:description: This example demonstrates a usage of Boto3 AWS client and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `Boto3 <https://github.com/boto/boto3>`_.
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/boto3-session>`_.
Listing of ``boto3_session_example.py``:
.. literalinclude:: ../../examples/miniapps/boto3-session/boto3_session_example.py
:language: python
.. include:: ../sponsor.rst
.. disqus::

View File

@ -1,77 +0,0 @@
Bundles mini application example
--------------------------------
.. currentmodule:: dependency_injector.containers
"Bundles" is an example mini application that is intented to demonstrate the
power of dependency injection for creation of re-usable application components
("bundles") with 100% transparency of their dependencies.
Example application
~~~~~~~~~~~~~~~~~~~
"Bundles" mini application has next structure:
.. code-block:: bash
bundles/
bundles/ <-- Bundles package
photos/ <-- Photos bundle
__init__.py <-- Photos bundle dependency injection container
entities.py
repositories.py
users/ <-- Users bundle
__init__.py <-- Users bundle dependency injection container
entities.py
repositories.py
run.py <-- Entrypoint
IoC containers
~~~~~~~~~~~~~~
Next two listings show :py:class:`DeclarativeContainer`'s for "users" and
"photos" bundles.
Listing of ``bundeles/users/__init__.py``:
.. literalinclude:: ../../examples/miniapps/bundles/bundles/users/__init__.py
:language: python
:linenos:
.. note::
- ``Users`` container has dependency on database.
Listing of ``bundeles/photos/__init__.py``:
.. literalinclude:: ../../examples/miniapps/bundles/bundles/photos/__init__.py
:language: python
:linenos:
.. note::
- ``Photos`` container has dependencies on database and file storage.
Run application
~~~~~~~~~~~~~~~
Finally, both "bundles" are initialized by providing needed dependencies.
Initialization of dependencies happens right in the runtime, not earlier.
Generally, it means, that any part of any bundle could be overridden on the
fly.
Listing of ``run.py``:
.. literalinclude:: ../../examples/miniapps/bundles/run.py
:language: python
:linenos:
Links
~~~~~
+ `Dependency Injector <https://github.com/ets-labs/python-dependency-injector/>`_
+ `Full example sources <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/bundles>`_
.. disqus::

View File

@ -1,22 +0,0 @@
Chained Factories pattern
=========================
This example demonstrate implementation of "Chained Factories" pattern.
Main idea of this pattern is about wrapping `Factory` into other `Factory`
that mix additional arguments or keyword arguments to a wrapped one.
Listing of ``data.py``, demonstrates sample classes structure:
.. literalinclude:: ../../examples/miniapps/factory_patterns/data.py
:language: python
:linenos:
Listing of ``chained_factories.py``, demonstrates "Chained Factories"
pattern and provide some explanation:
.. literalinclude:: ../../examples/miniapps/factory_patterns/chained_factories.py
:language: python
:linenos:
.. disqus::

View File

@ -0,0 +1,134 @@
.. _decoupled-packages:
Decoupled packages example (multiple containers)
================================================
.. meta::
:keywords: Python,Dependency Injection,Inversion of Control,Container,Example,Application,
Framework,AWS,boto3,client
:description: This example shows how to use Dependency Injector to create Python decoupled packages.
To achieve a decoupling each package has a container with the components. When
a component needs a dependency from the outside of the package scope we use the
Dependency provider. The package container has no knowledge on where the
dependencies come from. It states a need that the dependencies must be provided.
This helps to decouple a package from the 3rd party dependencies and other
packages.
This example shows how to use ``Dependency Injector`` to create decoupled packages.
To achieve a decoupling each package has a container with the components. When a component needs a
dependency from the outside of the package scope we use the ``Dependency`` provider. The package
container has no knowledge on where the dependencies come from. It states a need that the
dependencies must be provided. This helps to decouple a package from the 3rd party dependencies
and other packages.
To wire the packages we use an application container. Application container has all 3rd party
dependencies and package containers. It wires the packages and dependencies to create a
complete application.
We build an example micro application that consists of 3 packages:
- ``user`` - a package with user domain logic, depends on a database
- ``photo`` - a package with photo domain logic, depends on a database and AWS S3
- ``analytics`` - a package with analytics domain logic, depends on the ``user`` and ``photo``
package components
.. image:: images/decoupled-packages.png
:width: 100%
:align: center
Start from the scratch or jump to the section:
.. contents::
:local:
:backlinks: none
You can find the source code and instructions for running on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/decoupled-packages>`_.
Application structure
---------------------
Application consists of an ``example`` package, a configuration file and a ``requirements.txt``
file.
.. code-block:: bash
./
├── example/
│ ├── analytics/
│ │ ├── __init__.py
│ │ ├── containers.py
│ │ └── services.py
│ ├── photo/
│ │ ├── __init__.py
│ │ ├── containers.py
│ │ ├── entities.py
│ │ └── repositories.py
│ ├── user/
│ │ ├── __init__.py
│ │ ├── containers.py
│ │ ├── entities.py
│ │ └── repositories.py
│ ├── __init__.py
│ ├── __main__.py
│ └── containers.py
├── config.ini
└── requirements.txt
Package containers
------------------
Listing of the ``example/user/containers.py``:
.. literalinclude:: ../../examples/miniapps/decoupled-packages/example/user/containers.py
:language: python
Listing of the ``example/photo/containers.py``:
.. literalinclude:: ../../examples/miniapps/decoupled-packages/example/photo/containers.py
:language: python
Listing of the ``example/analytics/containers.py``:
.. literalinclude:: ../../examples/miniapps/decoupled-packages/example/analytics/containers.py
:language: python
Application container
---------------------
Application container consists of all packages and 3rd party dependencies. Its role is to wire
everything together in a complete application.
Listing of the ``example/containers.py``:
.. literalinclude:: ../../examples/miniapps/decoupled-packages/example/containers.py
:language: python
.. note::
Package ``analytics`` has dependencies on the repositories from the ``user`` and
``photo`` packages. This is an example of how you can pass the dependencies from one package
to another.
Main module
-----------
Listing of the ``example/__main__.py``:
.. literalinclude:: ../../examples/miniapps/decoupled-packages/example/__main__.py
:language: python
Configuration
-------------
Listing of the ``config.ini``:
.. literalinclude:: ../../examples/miniapps/decoupled-packages/config.ini
:language: ini
Run the application
-------------------
You can find the source code and instructions for running on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/decoupled-packages>`_.
.. include:: ../sponsor.rst
.. disqus::

99
docs/examples/django.rst Normal file
View File

@ -0,0 +1,99 @@
.. _django-example:
Django example
==============
.. meta::
:keywords: Python,Dependency Injection,Django,Example
:description: This example demonstrates a usage of the Django and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `Django <https://www.djangoproject.com/>`_.
The example application helps to search for repositories on the Github.
.. image:: images/django.png
:width: 100%
:align: center
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/django>`_.
Application structure
---------------------
Application has standard Django project structure. It consists of ``githubnavigator`` project package and
``web`` application package:
.. code-block:: bash
./
├── githubnavigator/
│ ├── __init__.py
│ ├── asgi.py
│ ├── containers.py
│ ├── services.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── web/
│ ├── templates/
│ │ ├── base.html
│ │ └── index.html
│ ├── __init__.py
│ ├── apps.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── manage.py
└── requirements.txt
Container
---------
Declarative container is defined in ``githubnavigator/containers.py``:
.. literalinclude:: ../../examples/miniapps/django/githubnavigator/containers.py
:language: python
Container instance is created in ``githubnavigator/__init__.py``:
.. literalinclude:: ../../examples/miniapps/django/githubnavigator/__init__.py
:language: python
Views
-----
View has dependencies on search service and some config options. The dependencies are injected
using :ref:`wiring` feature.
Listing of ``web/views.py``:
.. literalinclude:: ../../examples/miniapps/django/web/views.py
:language: python
App config
----------
Container is wired to the ``views`` module in the app config ``web/apps.py``:
.. literalinclude:: ../../examples/miniapps/django/web/apps.py
:language: python
:emphasize-lines: 12
Tests
-----
Tests use :ref:`provider-overriding` feature to replace github client with a mock ``web/tests.py``:
.. literalinclude:: ../../examples/miniapps/django/web/tests.py
:language: python
:emphasize-lines: 39,60
Sources
-------
Explore the sources on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/django>`_.
.. include:: ../sponsor.rst
.. disqus::

View File

@ -1,22 +0,0 @@
Factory of Factories pattern
============================
This example demonstrate implementation of "Factory of Factories" pattern.
Main idea of this pattern is about creation of a :py:class:`Factory` that
creates another :py:class:`Factory` and mix additional arguments to it.
Listing of ``data.py``, demonstrates sample classes structure:
.. literalinclude:: ../../examples/miniapps/factory_patterns/data.py
:language: python
:linenos:
Listing of ``factory_of_factories.py``, demonstrates "Chained Factories"
pattern and provide some explanation:
.. literalinclude:: ../../examples/miniapps/factory_patterns/factory_of_factories.py
:language: python
:linenos:
.. disqus::

View File

@ -0,0 +1,100 @@
.. _fastapi-redis-example:
FastAPI + Redis example
=======================
.. meta::
:keywords: Python,Dependency Injection,FastAPI,Redis,Example
:description: This example demonstrates a usage of the FastAPI, Redis, and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `FastAPI <https://fastapi.tiangolo.com/>`_ and
`Redis <https://redis.io/>`_.
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/fastapi-redis>`_.
See also:
- Provider :ref:`async-injections`
- Resource provider :ref:`resource-async-initializers`
- Wiring :ref:`async-injections-wiring`
Application structure
---------------------
Application has next structure:
.. code-block:: bash
./
├── fastapiredis/
│ ├── __init__.py
│ ├── application.py
│ ├── containers.py
│ ├── redis.py
│ ├── services.py
│ └── tests.py
├── docker-compose.yml
├── Dockerfile
└── requirements.txt
Redis
-----
Module ``redis`` defines Redis connection pool initialization and shutdown. See ``fastapiredis/redis.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-redis/fastapiredis/redis.py
:language: python
Service
-------
Module ``services`` contains example service. Service has a dependency on Redis connection pool.
It uses it for getting and setting a key asynchronously. Real life service will do something more meaningful.
See ``fastapiredis/services.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-redis/fastapiredis/services.py
:language: python
Container
---------
Declarative container wires example service with Redis connection pool. See ``fastapiredis/containers.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-redis/fastapiredis/containers.py
:language: python
Application
-----------
Module ``application`` creates ``FastAPI`` app, setup endpoint, and init container.
Endpoint ``index`` has a dependency on example service. The dependency is injected using :ref:`wiring` feature.
Listing of ``fastapiredis/application.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-redis/fastapiredis/application.py
:language: python
Tests
-----
Tests use :ref:`provider-overriding` feature to replace example service with a mock. See ``fastapiredis/tests.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-redis/fastapiredis/tests.py
:language: python
:emphasize-lines: 24
Sources
-------
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/fastapi-redis>`_.
See also:
- Provider :ref:`async-injections`
- Resource provider :ref:`resource-async-initializers`
- Wiring :ref:`async-injections-wiring`
.. include:: ../sponsor.rst
.. disqus::

View File

@ -0,0 +1,121 @@
.. _fastapi-sqlalchemy-example:
FastAPI + SQLAlchemy example
============================
.. meta::
:keywords: Python,Dependency Injection,FastAPI,SQLAlchemy,Example
:description: This example demonstrates a usage of the FastAPI, SQLAlchemy, and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `FastAPI <https://fastapi.tiangolo.com/>`_ and
`SQLAlchemy <https://www.sqlalchemy.org/>`_.
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/fastapi-sqlalchemy>`_.
Thanks to `@ShvetsovYura <https://github.com/ShvetsovYura>`_ for providing initial example:
`FastAPI_DI_SqlAlchemy <https://github.com/ShvetsovYura/FastAPI_DI_SqlAlchemy>`_.
Application structure
---------------------
Application has next structure:
.. code-block:: bash
./
├── webapp/
│ ├── __init__.py
│ ├── application.py
│ ├── containers.py
│ ├── database.py
│ ├── endpoints.py
│ ├── models.py
│ ├── repositories.py
│ ├── services.py
│ └── tests.py
├── config.yml
├── docker-compose.yml
├── Dockerfile
└── requirements.txt
Application factory
-------------------
Application factory creates container, wires it with the ``endpoints`` module, creates
``FastAPI`` app, and setup routes.
Application factory also creates database if it does not exist.
Listing of ``webapp/application.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-sqlalchemy/webapp/application.py
:language: python
Endpoints
---------
Module ``endpoints`` contains example endpoints. Endpoints have a dependency on user service.
User service is injected using :ref:`wiring` feature. See ``webapp/endpoints.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-sqlalchemy/webapp/endpoints.py
:language: python
Container
---------
Declarative container wires example user service, user repository, and utility database class.
See ``webapp/containers.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-sqlalchemy/webapp/containers.py
:language: python
Services
--------
Module ``services`` contains example user service. See ``webapp/services.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-sqlalchemy/webapp/services.py
:language: python
Repositories
------------
Module ``repositories`` contains example user repository. See ``webapp/repositories.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-sqlalchemy/webapp/repositories.py
:language: python
Models
------
Module ``models`` contains example SQLAlchemy user model. See ``webapp/models.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-sqlalchemy/webapp/models.py
:language: python
Database
--------
Module ``database`` defines declarative base and utility class with engine and session factory.
See ``webapp/database.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-sqlalchemy/webapp/database.py
:language: python
Tests
-----
Tests use :ref:`provider-overriding` feature to replace repository with a mock. See ``webapp/tests.py``:
.. literalinclude:: ../../examples/miniapps/fastapi-sqlalchemy/webapp/tests.py
:language: python
:emphasize-lines: 25, 45, 58, 74, 86, 97
Sources
-------
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/fastapi-sqlalchemy>`_.
.. include:: ../sponsor.rst
.. disqus::

81
docs/examples/fastapi.rst Normal file
View File

@ -0,0 +1,81 @@
.. _fastapi-example:
FastAPI example
===============
.. meta::
:keywords: Python,Dependency Injection,FastAPI,Example
:description: This example demonstrates a usage of the FastAPI and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `FastAPI <https://fastapi.tiangolo.com/>`_.
The example application is a REST API that searches for funny GIFs on the `Giphy <https://giphy.com/>`_.
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/fastapi>`_.
Application structure
---------------------
Application has next structure:
.. code-block:: bash
./
├── giphynavigator/
│ ├── __init__.py
│ ├── application.py
│ ├── containers.py
│ ├── endpoints.py
│ ├── giphy.py
│ ├── services.py
│ └── tests.py
├── config.yml
└── requirements.txt
Container
---------
Declarative container is defined in ``giphynavigator/containers.py``:
.. literalinclude:: ../../examples/miniapps/fastapi/giphynavigator/containers.py
:language: python
Endpoints
---------
Endpoint has a dependency on search service. There are also some config options that are used as default values.
The dependencies are injected using :ref:`wiring` feature.
Listing of ``giphynavigator/endpoints.py``:
.. literalinclude:: ../../examples/miniapps/fastapi/giphynavigator/endpoints.py
:language: python
Application factory
-------------------
Application factory creates container, wires it with the ``endpoints`` module, creates
``FastAPI`` app, and setup routes.
Listing of ``giphynavigator/application.py``:
.. literalinclude:: ../../examples/miniapps/fastapi/giphynavigator/application.py
:language: python
Tests
-----
Tests use :ref:`provider-overriding` feature to replace giphy client with a mock ``giphynavigator/tests.py``:
.. literalinclude:: ../../examples/miniapps/fastapi/giphynavigator/tests.py
:language: python
:emphasize-lines: 29,57,72
Sources
-------
Explore the sources on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/fastapi>`_.
.. include:: ../sponsor.rst
.. disqus::

View File

@ -0,0 +1,48 @@
.. _fastdepends-example:
FastDepends example
===================
.. meta::
:keywords: Python,Dependency Injection,FastDepends,Example
:description: This example demonstrates a usage of the FastDepends and Dependency Injector.
This example demonstrates how to use ``Dependency Injector`` with `FastDepends <https://github.com/Lancetnik/FastDepends>`_, a lightweight dependency injection framework inspired by FastAPI's dependency system, but without the web framework components.
Basic Usage
-----------
The integration between FastDepends and Dependency Injector is straightforward. Simply use Dependency Injector's ``Provide`` marker within FastDepends' ``Depends`` function:
.. code-block:: python
import sys
from dependency_injector import containers, providers
from dependency_injector.wiring import inject, Provide
from fast_depends import Depends
class CoefficientService:
@staticmethod
def get_coefficient() -> float:
return 1.2
class Container(containers.DeclarativeContainer):
service = providers.Factory(CoefficientService)
@inject
def apply_coefficient(
a: int,
coefficient_provider: CoefficientService = Depends(Provide[Container.service]),
) -> float:
return a * coefficient_provider.get_coefficient()
container = Container()
container.wire(modules=[sys.modules[__name__]])
apply_coefficient(100) == 120.0

View File

@ -0,0 +1,91 @@
.. _flask-blueprints-example:
Flask blueprints example
========================
.. meta::
:keywords: Python,Dependency Injection,Flask,Blueprints,Example
:description: This example demonstrates a usage of the Flask Blueprints and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `Flask <https://flask.palletsprojects.com/en/1.1.x/>`_
blueprints.
The example application helps to search for repositories on the Github.
.. image:: images/flask.png
:width: 100%
:align: center
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/flask-blueprints>`_.
Application structure
---------------------
Application has next structure:
.. code-block:: bash
./
├── githubnavigator/
│ ├── blueprints
│ │ ├── __init__.py
│ │ └── example.py
│ ├── templates
│ │ ├── base.html
│ │ └── index.py
│ ├── __init__.py
│ ├── application.py
│ ├── containers.py
│ ├── services.py
│ └── tests.py
├── config.yml
└── requirements.txt
Container
---------
Declarative container is defined in ``githubnavigator/containers.py``:
.. literalinclude:: ../../examples/miniapps/flask-blueprints/githubnavigator/containers.py
:language: python
Blueprints
----------
Blueprint's view has dependencies on search service and some config options. The dependencies are injected
using :ref:`wiring` feature.
Listing of ``githubnavigator/blueprints/example.py``:
.. literalinclude:: ../../examples/miniapps/flask-blueprints/githubnavigator/blueprints/example.py
:language: python
Application factory
-------------------
Application factory creates container, wires it with the blueprints, creates
``Flask`` app, and setup routes.
Listing of ``githubnavigator/application.py``:
.. literalinclude:: ../../examples/miniapps/flask-blueprints/githubnavigator/application.py
:language: python
Tests
-----
Tests use :ref:`provider-overriding` feature to replace github client with a mock ``githubnavigator/tests.py``:
.. literalinclude:: ../../examples/miniapps/flask-blueprints/githubnavigator/tests.py
:language: python
:emphasize-lines: 44,67
Sources
-------
Explore the sources on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/flask-blueprints>`_.
.. include:: ../sponsor.rst
.. disqus::

89
docs/examples/flask.rst Normal file
View File

@ -0,0 +1,89 @@
.. _flask-example:
Flask example
=============
.. meta::
:keywords: Python,Dependency Injection,Flask,Example
:description: This example demonstrates a usage of the Flask and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `Flask <https://flask.palletsprojects.com/en/1.1.x/>`_.
The example application helps to search for repositories on the Github.
.. image:: images/flask.png
:width: 100%
:align: center
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/flask>`_.
:ref:`flask-tutorial` demonstrates how to build this application step-by-step.
Application structure
---------------------
Application has next structure:
.. code-block:: bash
./
├── githubnavigator/
│ ├── templates
│ │ ├── base.html
│ │ └── index.py
│ ├── __init__.py
│ ├── application.py
│ ├── containers.py
│ ├── services.py
│ ├── tests.py
│ └── views.py
├── config.yml
└── requirements.txt
Container
---------
Declarative container is defined in ``githubnavigator/containers.py``:
.. literalinclude:: ../../examples/miniapps/flask/githubnavigator/containers.py
:language: python
Views
-----
View has dependencies on search service and some config options. The dependencies are injected
using :ref:`wiring` feature.
Listing of ``githubnavigator/views.py``:
.. literalinclude:: ../../examples/miniapps/flask/githubnavigator/views.py
:language: python
Application factory
-------------------
Application factory creates container, wires it with the ``views`` module, creates
``Flask`` app and setup routes.
Listing of ``githubnavigator/application.py``:
.. literalinclude:: ../../examples/miniapps/flask/githubnavigator/application.py
:language: python
Tests
-----
Tests use :ref:`provider-overriding` feature to replace github client with a mock ``githubnavigator/tests.py``:
.. literalinclude:: ../../examples/miniapps/flask/githubnavigator/tests.py
:language: python
:emphasize-lines: 44,67
Sources
-------
Explore the sources on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/flask>`_.
.. include:: ../sponsor.rst
.. disqus::

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 647 KiB

View File

@ -2,24 +2,26 @@ Examples
========
.. meta::
:keywords: Python,DI,Dependency injection,IoC,Inversion of Control
:description: Current section of documentation is designed to provide
several example mini applications that are built on the top
of inversion of control principle and powered by
"Dependency Injector" framework.
:keywords: Python,DI,Dependency injection,IoC,Inversion of Control,Example
:description: Python dependency injection examples.
Current section of documentation is designed to provide several example mini
applications that are built according to the inversion of control principle
and powered by *Dependency Injector* framework.
Explore the examples to see the ``Dependency Injector`` in action.
.. toctree::
:maxdepth: 2
movie_lister
services_miniapp_v1
services_miniapp_v2
bundles_miniapp
use_cases_miniapp
password_hashing_miniapp
chained_factories
factory_of_factories
application-single-container
application-multiple-containers
decoupled-packages
boto3
django
flask
flask-blueprints
aiohttp
sanic
fastapi
fastapi-redis
fastapi-sqlalchemy
fastdepends
.. disqus::

View File

@ -1,130 +0,0 @@
Movie lister naive example
--------------------------
.. meta::
:description: Movie lister - is a naive example of dependency injection and
inversion of control containers on Python. Original example
was taken from Martin Fowler's article about dependency
injection and inversion of control.
This naive example was taken from Martin Fowler's article about dependency
injection and inversion of control: http://www.martinfowler.com/articles/injection.html
Like Martin says:
.. pull-quote::
*Like all of my examples it's one of those super-simple examples;
small enough to be unreal, but hopefully enough for you to visualize
what's going on without falling into the bog of a real example.*
While original Martin's MovieLister example was a bit modified here, it
makes sense to provide some description. So, the idea of this example is to
create ``movies`` library that can be configured to work with different
movie databases (csv, sqlite, etc...) and provide 2 main features:
1. List all movies that were directed by certain person.
2. List all movies that were released in certain year.
Also this example contains 3 mini applications that are based on ``movies``
library:
1. ``app_csv.py`` - list movies by certain criteria from csv file database.
2. ``app_db.py`` - list movies by certain criteria from sqlite database.
3. ``app_db_csv.py`` - list movies by certain criteria from csv file and
sqlite databases.
Instructions for running:
.. code-block:: bash
python app_csv.py
python app_db.py
python app_db_csv.py
Full code of example could be found on GitHub_.
Movies library
~~~~~~~~~~~~~~
Classes diagram:
.. image:: /images/miniapps/movie_lister/classes.png
:width: 100%
:align: center
Movies library structure:
.. code-block:: bash
/movies
/__init__.py
/finders.py
/listers.py
/models.py
Listing of ``movies/__init__.py``:
.. literalinclude:: ../../examples/miniapps/movie_lister/movies/__init__.py
:language: python
:linenos:
Example application
~~~~~~~~~~~~~~~~~~~
Example application structure:
.. code-block:: bash
/example
/__init__.py
/db.py
/main.py
Listing of ``examples/main.py``:
.. literalinclude:: ../../examples/miniapps/movie_lister/example/main.py
:language: python
:linenos:
Listing of ``examples/db.py``:
.. literalinclude:: ../../examples/miniapps/movie_lister/example/db.py
:language: python
:linenos:
Csv application
~~~~~~~~~~~~~~~
Listing of ``app_csv.py``:
.. literalinclude:: ../../examples/miniapps/movie_lister/app_csv.py
:language: python
:linenos:
Database application
~~~~~~~~~~~~~~~~~~~~
Listing of ``app_db.py``:
.. literalinclude:: ../../examples/miniapps/movie_lister/app_db.py
:language: python
:linenos:
Csv and database application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Listing of ``app_db_csv.py``:
.. literalinclude:: ../../examples/miniapps/movie_lister/app_db_csv.py
:language: python
:linenos:
.. disqus::
.. _GitHub: https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/movie_lister

View File

@ -1,19 +0,0 @@
Dependency injection and password hashing in Python
===================================================
Small example that demonstrates using of dependency injection for user
password hashing.
Instructions for running:
.. code-block:: bash
python example.py
Listing of ``example.py``:
.. literalinclude:: ../../examples/miniapps/password_hashing/example.py
:language: python
:linenos:
.. disqus::

82
docs/examples/sanic.rst Normal file
View File

@ -0,0 +1,82 @@
.. _sanic-example:
Sanic example
==============
.. meta::
:keywords: Python,Dependency Injection,Sanic,Example
:description: This example demonstrates a usage of the Sanic and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `Sanic <https://sanic.readthedocs.io/en/latest/>`_.
The example application is a REST API that searches for funny GIFs on the `Giphy <https://giphy.com/>`_.
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/sanic>`_.
Application structure
---------------------
Application has next structure:
.. code-block:: bash
./
├── giphynavigator/
│ ├── __init__.py
│ ├── __main__.py
│ ├── application.py
│ ├── containers.py
│ ├── giphy.py
│ ├── handlers.py
│ ├── services.py
│ └── tests.py
├── config.yml
└── requirements.txt
Container
---------
Declarative container is defined in ``giphynavigator/containers.py``:
.. literalinclude:: ../../examples/miniapps/sanic/giphynavigator/containers.py
:language: python
Handlers
--------
Handler has dependencies on search service and some config options. The dependencies are injected
using :ref:`wiring` feature.
Listing of ``giphynavigator/handlers.py``:
.. literalinclude:: ../../examples/miniapps/sanic/giphynavigator/handlers.py
:language: python
Application factory
-------------------
Application factory creates container, wires it with the ``handlers`` module, creates
``Sanic`` app and setup routes.
Listing of ``giphynavigator/application.py``:
.. literalinclude:: ../../examples/miniapps/sanic/giphynavigator/application.py
:language: python
Tests
-----
Tests use :ref:`provider-overriding` feature to replace giphy client with a mock ``giphynavigator/tests.py``:
.. literalinclude:: ../../examples/miniapps/sanic/giphynavigator/tests.py
:language: python
:emphasize-lines: 34,61,75
Sources
-------
Explore the sources on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/sanic>`_.
.. include:: ../sponsor.rst
.. disqus::

View File

@ -1,77 +0,0 @@
Services mini application example (v1 - multiple containers)
------------------------------------------------------------
.. meta::
:description: "Services miniapp" is an example mini application that
consists from several services that have dependencies on
some standard and 3rd-party libraries for logging,
interaction with database and remote service via API.
"Services miniapp" example demonstrates usage of
Dependency Injector for creating several inversion of control /
dependency injection containers.
"Services miniapp" is an example mini application that consists from several
services that have dependencies on some standard and 3rd-party libraries for
logging, interaction with database and remote service calls via API.
"Services miniapp" example demonstrates usage of
:doc:`Dependency Injector <../index>` for creating several IoC containers.
Instructions for running:
.. code-block:: bash
python run.py 1 secret photo.jpg
Example application
~~~~~~~~~~~~~~~~~~~
Classes diagram:
.. image:: /images/miniapps/services/classes.png
:width: 100%
:align: center
Example application structure:
.. code-block:: bash
/example
/__init__.py
/main.py
/services.py
Listing of ``example/services.py``:
.. literalinclude:: ../../examples/miniapps/services_v1/example/services.py
:language: python
:linenos:
Listing of ``example/main.py``:
.. literalinclude:: ../../examples/miniapps/services_v1/example/main.py
:language: python
:linenos:
IoC containers
~~~~~~~~~~~~~~
Listing of ``containers.py``:
.. literalinclude:: ../../examples/miniapps/services_v1/containers.py
:language: python
:linenos:
Run application
~~~~~~~~~~~~~~~
Listing of ``run.py``:
.. literalinclude:: ../../examples/miniapps/services_v1/run.py
:language: python
:linenos:
.. disqus::

View File

@ -1,77 +0,0 @@
Services mini application example (v2 - single container)
---------------------------------------------------------
.. meta::
:description: "Services miniapp" is an example mini application that
consists from several services that have dependencies on
some standard and 3rd-party libraries for logging,
interaction with database and remote service via API.
"Services miniapp" example demonstrates usage of
Dependency Injector for creating inversion of control /
dependency injection container.
"Services miniapp" is an example mini application that consists from several
services that have dependencies on some standard and 3rd-party libraries for
logging, interaction with database and remote service calls via API.
"Services miniapp" example demonstrates usage of
:doc:`Dependency Injector <../index>` for creating IoC container.
Instructions for running:
.. code-block:: bash
python run.py 1 secret photo.jpg
Example application
~~~~~~~~~~~~~~~~~~~
Classes diagram:
.. image:: /images/miniapps/services/classes.png
:width: 100%
:align: center
Example application structure:
.. code-block:: bash
/example
/__init__.py
/main.py
/services.py
Listing of ``example/services.py``:
.. literalinclude:: ../../examples/miniapps/services_v2/example/services.py
:language: python
:linenos:
Listing of ``example/main.py``:
.. literalinclude:: ../../examples/miniapps/services_v2/example/main.py
:language: python
:linenos:
IoC container
~~~~~~~~~~~~~
Listing of ``container.py``:
.. literalinclude:: ../../examples/miniapps/services_v2/container.py
:language: python
:linenos:
Run application
~~~~~~~~~~~~~~~
Listing of ``run.py``:
.. literalinclude:: ../../examples/miniapps/services_v2/run.py
:language: python
:linenos:
.. disqus::

View File

@ -1,57 +0,0 @@
Use cases mini application example
----------------------------------
.. currentmodule:: dependency_injector.providers
"Use cases" miniapp demonstrate usage of :py:class:`DependenciesContainer`
provider.
Example application
~~~~~~~~~~~~~~~~~~~
"Use cases" mini application has next structure:
.. code-block:: bash
use_cases/
example/ <-- Example package
__init__.py
adapters.py
use_cases.py
containers.py <-- Dependency injection containers
run.py <-- Entrypoint
IoC containers
~~~~~~~~~~~~~~
Listing of ``use_cases/containers.py``:
.. literalinclude:: ../../examples/miniapps/use_cases/containers.py
:language: python
:linenos:
Run application
~~~~~~~~~~~~~~~
Listing of ``run.py``:
.. literalinclude:: ../../examples/miniapps/use_cases/run.py
:language: python
:linenos:
Instructions for running:
.. code-block:: bash
python run.py prod example@example.com # Running in "production" environment
python run.py test example@example.com # Running in "testing" environment
Links
~~~~~
+ `Dependency Injector <https://github.com/ets-labs/python-dependency-injector/>`_
+ `Full example sources <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/use_cases>`_
.. disqus::

BIN
docs/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View File

@ -1,90 +1,150 @@
======================================================================
Dependency Injector --- Dependency injection microframework for Python
======================================================================
=================================================================
Dependency Injector --- Dependency injection framework for Python
=================================================================
.. meta::
:google-site-verification: 6it89zX0_wccKEhAqbAiYQooS95f0BA8YfesHk6bsNA
:google-site-verification: V1hlKfpgL3AARAElwFcqP4qW1Smsx5bKSRU8O86i20Y
:keywords: Python,Dependency injection,DI,Inversion of Control,IoC,
IoC Container,Factory, Singleton, Design Patterns
:description: Dependency Injector is a dependency injection microframework
for Python. It was designed to be unified, developer-friendly
tool that helps to implement dependency injection design
pattern in formal, pretty, Pythonic way. Dependency Injector
provides implementations of such popular design patterns
like IoC container, Factory and Singleton. Dependency
Injector providers are implemented as C extension types
:description: Dependency Injector is a dependency injection framework
for Python. It helps to maintain you application structure.
It was designed to be unified, developer-friendly
tool that helps to implement dependency injection design
pattern in formal, pretty, Pythonic way. Dependency Injector
provides implementations of such popular design patterns
like IoC container, Factory and Singleton. Dependency
Injector providers are implemented as C extension types
using Cython.
.. _index:
*Dependency Injector* is a dependency injection microframework for Python.
It was designed to be unified, developer-friendly tool that helps to implement
dependency injection design pattern in formal, pretty, Pythonic way.
.. image:: https://img.shields.io/pypi/v/dependency_injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: Latest Version
*Dependency Injector* framework key features are:
.. image:: https://img.shields.io/pypi/l/dependency_injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: License
+ Easy, smart, pythonic style.
+ Obvious, clear structure.
+ Extensibility and flexibility.
+ High performance.
+ Memory efficiency.
+ Thread safety.
+ Documentation.
+ Semantic versioning.
.. image:: https://img.shields.io/pypi/pyversions/dependency_injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: Supported Python versions
*Dependency Injector* containers and providers are implemented as C extension
types using Cython.
.. image:: https://img.shields.io/pypi/implementation/dependency_injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: Supported Python implementations
Status
------
.. image:: https://static.pepy.tech/badge/dependency-injector
:target: https://pepy.tech/project/dependency-injector
:alt: Downloads
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
| *PyPi* | .. image:: https://img.shields.io/pypi/v/dependency_injector.svg |
| | :target: https://pypi.python.org/pypi/dependency_injector/ |
| | :alt: Latest Version |
| | .. image:: https://img.shields.io/pypi/l/dependency_injector.svg |
| | :target: https://pypi.python.org/pypi/dependency_injector/ |
| | :alt: License |
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
| *Python versions and implementations* | .. image:: https://img.shields.io/pypi/pyversions/dependency_injector.svg |
| | :target: https://pypi.python.org/pypi/dependency_injector/ |
| | :alt: Supported Python versions |
| | .. image:: https://img.shields.io/pypi/implementation/dependency_injector.svg |
| | :target: https://pypi.python.org/pypi/dependency_injector/ |
| | :alt: Supported Python implementations |
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
| *Builds and tests coverage* | .. image:: https://travis-ci.org/ets-labs/python-dependency-injector.svg?branch=master |
| | :target: https://travis-ci.org/ets-labs/python-dependency-injector |
| | :alt: Build Status |
| | .. image:: http://readthedocs.org/projects/python-dependency-injector/badge/?version=latest |
| | :target: http://python-dependency-injector.ets-labs.org/ |
| | :alt: Docs Status |
| | .. image:: https://coveralls.io/repos/github/ets-labs/python-dependency-injector/badge.svg?branch=master |
| | :target: https://coveralls.io/github/ets-labs/python-dependency-injector?branch=master |
| | :alt: Coverage Status |
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
| *Github* | .. image:: https://img.shields.io/github/watchers/ets-labs/python-dependency-injector.svg?style=social&label=Watch |
| | :target: https://github.com/ets-labs/python-dependency-injector |
| | :alt: Github watchers |
| | .. image:: https://img.shields.io/github/stars/ets-labs/python-dependency-injector.svg?style=social&label=Star |
| | :target: https://github.com/ets-labs/python-dependency-injector |
| | :alt: Github stargazers |
| | .. image:: https://img.shields.io/github/forks/ets-labs/python-dependency-injector.svg?style=social&label=Fork |
| | :target: https://github.com/ets-labs/python-dependency-injector |
| | :alt: Github forks |
+---------------------------------------+--------------------------------------------------------------------------------------------------------------------+
.. image:: https://static.pepy.tech/badge/dependency-injector/month
:target: https://pepy.tech/project/dependency-injector
:alt: Downloads
.. image:: https://static.pepy.tech/badge/dependency-injector/week
:target: https://pepy.tech/project/dependency-injector
:alt: Downloads
.. image:: https://img.shields.io/pypi/wheel/dependency-injector.svg
:target: https://pypi.org/project/dependency-injector/
:alt: Wheel
.. image:: https://img.shields.io/github/actions/workflow/status/ets-labs/python-dependency-injector/tests-and-linters.yml?branch=master
:target: https://github.com/ets-labs/python-dependency-injector/actions
:alt: Build Status
.. image:: https://coveralls.io/repos/github/ets-labs/python-dependency-injector/badge.svg?branch=master
:target: https://coveralls.io/github/ets-labs/python-dependency-injector?branch=master
:alt: Coverage Status
``Dependency Injector`` is a dependency injection framework for Python.
It helps implementing the dependency injection principle.
Key features of the ``Dependency Injector``:
- **Providers**. Provides ``Factory``, ``Singleton``, ``Callable``, ``Coroutine``, ``Object``,
``List``, ``Dict``, ``Configuration``, ``Resource``, ``Dependency``, and ``Selector`` providers
that help assemble your objects. See :ref:`providers`.
- **Overriding**. Can override any provider by another provider on the fly. This helps in testing
and configuring dev/stage environment to replace API clients with stubs etc. See
:ref:`provider-overriding`.
- **Configuration**. Reads configuration from ``yaml``, ``ini``, and ``json`` files, ``pydantic`` settings,
environment variables, and dictionaries. See :ref:`configuration-provider`.
- **Resources**. Helps with initialization and configuring of logging, event loop, thread
or process pool, etc. Can be used for per-function execution scope in tandem with wiring.
See :ref:`resource-provider`.
- **Containers**. Provides declarative and dynamic containers. See :ref:`containers`.
- **Wiring**. Injects dependencies into functions and methods. Helps integrate with
other frameworks: Django, Flask, Aiohttp, Sanic, FastAPI, etc. See :ref:`wiring`.
- **Asynchronous**. Supports asynchronous injections. See :ref:`async-injections`.
- **Typing**. Provides typing stubs, ``mypy``-friendly. See :ref:`provider-typing`.
- **Performance**. Fast. Written in ``Cython``.
- **Maturity**. Mature and production-ready. Well-tested, documented, and supported.
.. code-block:: python
from dependency_injector import containers, providers
from dependency_injector.wiring import Provide, inject
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,
)
@inject
def main(service: Service = Provide[Container.service]) -> None:
...
if __name__ == "__main__":
container = Container()
container.config.api_key.from_env("API_KEY", required=True)
container.config.timeout.from_env("TIMEOUT", as_=int, default=5)
container.wire(modules=[__name__])
main() # <-- dependency is injected automatically
with container.api_client.override(mock.Mock()):
main() # <-- overridden dependency is injected automatically
With the ``Dependency Injector``, object assembling is consolidated in the container.
Dependency injections are defined explicitly.
This makes it easier to understand and change how the application works.
.. figure:: https://raw.githubusercontent.com/wiki/ets-labs/python-dependency-injector/img/di-readme.svg
:target: https://github.com/ets-labs/python-dependency-injector
Explore the documentation to know more about the ``Dependency Injector``.
.. _contents:
Contents
--------
.. toctree::
:maxdepth: 2
.. toctree::
:maxdepth: 2
introduction/index
main/installation
providers/index
containers/index
examples/index
api/index
main/feedback
main/changelog
introduction/index
examples/index
tutorials/index
providers/index
containers/index
wiring
examples-other/index
api/index
main/feedback
main/changelog

View File

@ -1,144 +1,315 @@
Dependency injection and inversion of control in Python
-------------------------------------------------------
=======================================================
.. meta::
:keywords: Python,DI,Dependency injection,IoC,Inversion of Control
:description: This article describes benefits of dependency injection and
inversion of control for Python applications. Also it
contains some Python examples that show how dependency
injection and inversion could be implemented. In addition, it
demonstrates usage of dependency injection framework,
IoC container and such popular design pattern as Factory.
:keywords: Python,DI,Dependency injection,IoC,Inversion of Control,Example
:description: This page describes a usage of the dependency injection and inversion of control
in Python. It contains Python examples that show how to implement dependency
injection. It demonstrates a usage of the dependency injection framework
Dependency Injector, its container, Factory, Singleton and Configuration
providers. The example show how to use Dependency Injector providers overriding
feature for testing or configuring project in different environments and explains
why it's better than monkey-patching.
History
~~~~~~~
Originally dependency injection pattern got popular in languages with static typing like Java.
Dependency injection is a principle that helps to achieve an inversion of control. A
dependency injection framework can significantly improve the flexibility of a language
with static typing. Implementation of a dependency injection framework for a language
with static typing is not something that one can do quickly. It will be a quite complex thing
to be done well. And will take time.
Originally, dependency injection pattern got popular in languages with static
typing, like Java. Dependency injection framework can
significantly improve flexibility of the language with static typing. Also,
implementation of dependency injection framework for language with static
typing is not something that one can do shortly, it could be quite complex
thing to be done well.
Python is an interpreted language with dynamic typing. There is an opinion that dependency
injection doesn't work for it as well as it does for Java. A lot of the flexibility is already
built-in. Also, there is an opinion that a dependency injection framework is something that
Python developer rarely needs. Python developers say that dependency injection can be implemented
easily using language fundamentals.
While Python is very flexible interpreted language with dynamic typing, there
is a meaning that dependency injection doesn't work for it as well, as it does
for Java. Also there is a meaning that dependency injection framework is
something that Python developer would not ever need, cause dependency injection
could be implemented easily using language fundamentals.
This page describes the advantages of applying dependency injection in Python. It
contains Python examples that show how to implement dependency injection. It demonstrates the usage
of the ``Dependency Injector`` framework, its container, ``Factory``, ``Singleton``,
and ``Configuration`` providers. The example shows how to use providers' overriding feature
of ``Dependency Injector`` for testing or re-configuring a project in different environments and
explains why it's better than monkey-patching.
Discussion
~~~~~~~~~~
What is dependency injection?
-----------------------------
It is true.
Let's see what the dependency injection is.
Partly.
Dependency injection is a principle that helps to decrease coupling and increase cohesion.
Dependency injection, as a software design pattern, has number of
advantages that are common for each language (including Python):
.. image:: images/coupling-cohesion.png
+ Dependency Injection decreases coupling between a class and its dependency.
+ Because dependency injection doesn't require any change in code behavior it
can be applied to legacy code as a refactoring. The result is clients that
are more independent and that are easier to unit test in isolation using
stubs or mock objects that simulate other objects not under test. This ease
of testing is often the first benefit noticed when using dependency
injection.
+ Dependency injection can be used to externalize a system's configuration
details into configuration files allowing the system to be reconfigured
without recompilation (rebuilding). Separate configurations can be written
for different situations that require different implementations of
components. This includes, but is not limited to, testing.
+ Reduction of boilerplate code in the application objects since all work to
initialize or set up dependencies is handled by a provider component.
+ Dependency injection allows a client to remove all knowledge of a concrete
implementation that it needs to use. This helps isolate the client from the
impact of design changes and defects. It promotes reusability, testability
and maintainability.
+ Dependency injection allows a client the flexibility of being configurable.
Only the client's behavior is fixed. The client may act on anything that
supports the intrinsic interface the client expects.
What is coupling and cohesion?
.. note::
Coupling and cohesion are about how tough the components are tied.
While improved testability is one the first benefits of using dependency
injection, it could be easily overwhelmed by monkey-patching technique,
that works absolutely great in Python (you can monkey-patch anything,
anytime). At the same time, monkey-patching has nothing similar with
other advantages defined above. Also monkey-patching technique is
something that could be considered like too dirty to be used in production.
- **High coupling**. If the coupling is high it's like using superglue or welding. No easy way
to disassemble.
- **High cohesion**. High cohesion is like using screws. Quite easy to disassemble and
re-assemble in a different way. It is an opposite to high coupling.
The complexity of dependency injection pattern implementation in Python is
definitely quite lower than in other languages (even with dynamic typing).
Cohesion often correlates with coupling. Higher cohesion usually leads to lower coupling and vice versa.
.. note::
Low coupling brings flexibility. Your code becomes easier to change and test.
Low complexity of dependency injection pattern implementation in Python
still means that some code should be written, reviewed, tested and
supported.
How to implement the dependency injection?
Talking about inversion of control, it is a software design principle that
also works for each programming language, not dependending on its typing type.
Objects do not create each other anymore. They provide a way to inject the dependencies instead.
Inversion of control is used to increase modularity of the program and make
it extensible.
Before:
Main design purposes of using inversion of control are:
.. code-block:: python
+ To decouple the execution of a task from implementation.
+ To focus a module on the task it is designed for.
+ To free modules from assumptions about how other systems do what they do and
instead rely on contracts.
+ To prevent side effects when replacing a module.
import os
Example
~~~~~~~
Let's go through next example:
class ApiClient:
.. image:: /images/miniapps/engines_cars/diagram.png
:width: 100%
:align: center
def __init__(self) -> None:
self.api_key = os.getenv("API_KEY") # <-- dependency
self.timeout = int(os.getenv("TIMEOUT")) # <-- dependency
Listing of ``example.engines`` module:
.. literalinclude:: ../../examples/miniapps/engines_cars/example/engines.py
:language: python
:linenos:
class Service:
Listing of ``example.cars`` module:
def __init__(self) -> None:
self.api_client = ApiClient() # <-- dependency
.. literalinclude:: ../../examples/miniapps/engines_cars/example/cars.py
:language: python
:linenos:
Next example demonstrates creation of several cars with different engines:
def main() -> None:
service = Service() # <-- dependency
...
.. literalinclude:: ../../examples/miniapps/engines_cars/example_di.py
:language: python
:linenos:
While previous example demonstrates advantages of dependency injection, there
is a disadvantage demonstration as well - creation of car requires additional
code for specification of dependencies. Nevertheless, this disadvantage could
be easily avoided by using a dependency injection framework for creation of
inversion of control container (IoC container).
if __name__ == "__main__":
main()
Example of creation of several inversion of control containers (IoC containers)
using :doc:`Dependency Injector <../index>`:
After:
.. literalinclude:: ../../examples/miniapps/engines_cars/example_ioc_containers.py
:language: python
:linenos:
.. code-block:: python
Userful links
~~~~~~~~~~~~~
import os
There are some useful links related to dependency injection design pattern
that could be used for further reading:
class ApiClient:
def __init__(self, api_key: str, timeout: int) -> None:
self.api_key = api_key # <-- dependency is injected
self.timeout = timeout # <-- dependency is injected
class Service:
def __init__(self, api_client: ApiClient) -> None:
self.api_client = api_client # <-- dependency is injected
def main(service: Service) -> None: # <-- dependency is injected
...
if __name__ == "__main__":
main(
service=Service(
api_client=ApiClient(
api_key=os.getenv("API_KEY"),
timeout=int(os.getenv("TIMEOUT")),
),
),
)
``ApiClient`` is decoupled from knowing where the options come from. You can read a key and a
timeout from a configuration file or even get them from a database.
``Service`` is decoupled from the ``ApiClient``. It does not create it anymore. You can provide a
stub or other compatible object.
Function ``main()`` is decoupled from ``Service``. It receives it as an argument.
Flexibility comes with a price.
Now you need to assemble and inject the objects like this:
.. code-block:: python
main(
service=Service(
api_client=ApiClient(
api_key=os.getenv("API_KEY"),
timeout=int(os.getenv("TIMEOUT")),
),
),
)
The assembly code might get duplicated and it'll become harder to change the application structure.
Here comes the ``Dependency Injector``.
What does the Dependency Injector do?
-------------------------------------
With the dependency injection pattern, objects lose the responsibility of assembling
the dependencies. The ``Dependency Injector`` absorbs that responsibility.
``Dependency Injector`` helps to assemble and inject the dependencies.
It provides a container and providers that help you with the objects assembly.
When you need an object you place a ``Provide`` marker as a default value of a
function argument. When you call this function, framework assembles and injects
the dependency.
.. code-block:: python
from dependency_injector import containers, providers
from dependency_injector.wiring import Provide, inject
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,
)
@inject
def main(service: Service = Provide[Container.service]) -> None:
...
if __name__ == "__main__":
container = Container()
container.config.api_key.from_env("API_KEY", required=True)
container.config.timeout.from_env("TIMEOUT", as_=int, default=5)
container.wire(modules=[__name__])
main() # <-- dependency is injected automatically
with container.api_client.override(mock.Mock()):
main() # <-- overridden dependency is injected automatically
When you call the ``main()`` function the ``Service`` dependency is assembled and injected automatically.
When you do testing, you call the ``container.api_client.override()`` method to replace the real API
client with a mock. When you call ``main()``, the mock is injected.
You can override any provider with another provider.
It also helps you in a re-configuring project for different environments: replace an API client
with a stub on the dev or stage.
Objects assembling is consolidated in a container. Dependency injections are defined explicitly.
This makes it easier to understand and change how an application works.
Testing, Monkey-patching and dependency injection
-------------------------------------------------
The testability benefit is opposed to monkey-patching.
In Python, you can monkey-patch anything, anytime. The problem with monkey-patching is
that it's too fragile. The cause of it is that when you monkey-patch you do something that
wasn't intended to be done. You monkey-patch the implementation details. When implementation
changes the monkey-patching is broken.
With dependency injection, you patch the interface, not an implementation. This is a way more
stable approach.
Also, monkey-patching is way too dirty to be used outside of the testing code for
re-configuring the project for the different environments.
Conclusion
----------
Dependency injection provides you with three advantages:
- **Flexibility**. The components are loosely coupled. You can easily extend or change the
functionality of a system by combining the components in a different way. You even can do it on
the fly.
- **Testability**. Testing is easier because you can easily inject mocks instead of real objects
that use API or database, etc.
- **Clearness and maintainability**. Dependency injection helps you reveal the dependencies.
Implicit becomes explicit. And "Explicit is better than implicit" (PEP 20 - The Zen of Python).
You have all the components and dependencies defined explicitly in a container. This
provides an overview and control of the application structure. It is easier to understand and
change it.
Is it worth applying dependency injection in Python?
It depends on what you build. The advantages above are not too important if you use Python as a
scripting language. The picture is different when you use Python to create an application. The
larger the application the more significant the benefits.
Is it worth using a framework for applying dependency injection?
The complexity of the dependency injection pattern implementation in Python is
lower than in other languages but it's still in place. It doesn't mean you have to use a
framework but using a framework is beneficial because the framework is:
- Already implemented
- Tested on all platforms and versions of Python
- Documented
- Supported
- Other engineers are familiar with it
An advice at last:
- **Give it a try**. Dependency injection is counter-intuitive. Our nature is that
when we need something the first thought that comes to our mind is to go and get it. Dependency
injection is just like "Wait, I need to state a need instead of getting something right away".
It's like a little investment that will pay-off later. The advice is to just give it a try for
two weeks. This time will be enough for getting your own impression. If you don't like it you
won't lose too much.
- **Common sense first**. Use common sense when applying dependency injection. It is a good
principle, but not a silver bullet. If you do it too much you will reveal too many of the
implementation details. Experience comes with practice and time.
What's next?
------------
Choose one of the following as a next step:
- Look at the application examples:
- :ref:`application-single-container`
- :ref:`application-multiple-containers`
- :ref:`decoupled-packages`
- :ref:`boto3-example`
- :ref:`django-example`
- :ref:`flask-example`
- :ref:`flask-blueprints-example`
- :ref:`aiohttp-example`
- :ref:`sanic-example`
- :ref:`fastapi-example`
- :ref:`fastapi-redis-example`
- :ref:`fastapi-sqlalchemy-example`
- Pass the tutorials:
- :ref:`flask-tutorial`
- :ref:`aiohttp-tutorial`
- :ref:`asyncio-daemon-tutorial`
- :ref:`cli-tutorial`
- Know more about the ``Dependency Injector`` :ref:`key-features`
- Know more about the :ref:`providers`
- Know more about the :ref:`wiring`
- Go to the :ref:`contents`
Useful links
------------
A few useful links related to a dependency injection design pattern for further reading:
+ https://en.wikipedia.org/wiki/Dependency_injection
+ https://martinfowler.com/articles/injection.html
+ https://github.com/ets-labs/python-dependency-injector
+ https://pypi.python.org/pypi/dependency_injector
+ https://pypi.org/project/dependency-injector/
.. include:: ../sponsor.rst
.. disqus::

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -3,18 +3,16 @@ Introduction
.. meta::
:keywords: Python,DI,Dependency injection,IoC,Inversion of Control
:description: Current section of documentation is designed to give some
overview about dependency injection pattern, inversion of
control principle and "Dependency Injector" framework.
:description: Current section of the documentation is provides an
overview of the dependency injection, inversion of
control and Dependency Injector framework.
Current section of documentation is designed to give some overview about
dependency injection pattern, inversion of control principle and
*Dependency Injector* framework.
The current section of the documentation provides an overview of the
dependency injection, inversion of control, and the ``Dependency Injector`` framework.
.. toctree::
:maxdepth: 2
what_is_di
di_in_python
key_features
structure
installation

View File

@ -0,0 +1,42 @@
Installation
============
``Dependency Injector`` is available on `PyPI <https://pypi.org/project/dependency-injector/>`_.
To install the latest version you can use ``pip``:
.. code-block:: bash
pip install dependency-injector
Some modules of the ``Dependency Injector`` are implemented as C extensions.
``Dependency Injector`` is distributed as a pre-compiled wheels. Wheels are
available for all supported Python versions on Linux, Windows, and MacOS.
Linux distribution uses `manylinux <https://github.com/pypa/manylinux>`_.
If there is no appropriate wheel for your environment (Python version and OS)
installer will compile the package from sources on your machine. You'll need
a C compiler and Python header files.
To verify the installed version:
.. code-block:: bash
>>> import dependency_injector
>>> dependency_injector.__version__
'4.39.0'
.. note::
When adding ``Dependency Injector`` to ``pyproject.toml`` or ``requirements.txt``
don't forget to pin the version to the current major:
.. code-block:: bash
dependency-injector>=4.0,<5.0
*The next major version can be incompatible.*
All releases are available on the `PyPI release history page <https://pypi.org/project/dependency-injector/#history>`_.
Each release has an appropriate tag. The tags are available on the
`GitHub releases page <https://github.com/ets-labs/python-dependency-injector/releases>`_.
.. disqus::

View File

@ -1,48 +1,43 @@
Key features of Dependency Injector
-----------------------------------
.. _key-features:
Key features
------------
.. meta::
:keywords: Python,DI,Dependency injection,IoC,Inversion of Control
:description: This article describes key features of "Dependency Injector"
framework. It also provides some cases and recommendations
about usage of "Dependency Injector" framework.
:description: This article describes key features of the Dependency Injector
framework.
*Dependency Injector* is a dependency injection framework for Python projects.
It was designed to be unified, developer-friendly tool for managing any kind
of Python objects and their dependencies in formal, pretty way.
Key features of the ``Dependency Injector``:
*Dependency Injector* framework key features are:
- **Providers**. Provides ``Factory``, ``Singleton``, ``Callable``, ``Coroutine``, ``Object``,
``List``, ``Dict``, ``Configuration``, ``Resource``, ``Dependency``, and ``Selector`` providers
that help assemble your objects. See :ref:`providers`.
- **Overriding**. Can override any provider by another provider on the fly. This helps in testing
and configuring dev/stage environment to replace API clients with stubs etc. See
:ref:`provider-overriding`.
- **Configuration**. Reads configuration from ``yaml``, ``ini``, and ``json`` files, ``pydantic`` settings,
environment variables, and dictionaries. See :ref:`configuration-provider`.
- **Resources**. Helps with initialization and configuring of logging, event loop, thread
or process pool, etc. Can be used for per-function execution scope in tandem with wiring.
See :ref:`resource-provider`.
- **Containers**. Provides declarative and dynamic containers. See :ref:`containers`.
- **Wiring**. Injects dependencies into functions and methods. Helps integrate with
other frameworks: Django, Flask, Aiohttp, Sanic, FastAPI, etc. See :ref:`wiring`.
- **Asynchronous**. Supports asynchronous injections. See :ref:`async-injections`.
- **Typing**. Provides typing stubs, ``mypy``-friendly. See :ref:`provider-typing`.
- **Performance**. Fast. Written in ``Cython``.
- **Maturity**. Mature and production-ready. Well-tested, documented, and supported.
+ Easy, smart, pythonic style.
+ Obvious, clear structure.
+ Extensibility and flexibility.
+ Memory efficiency.
+ Thread safety.
+ Documentation.
+ Semantic versioning.
The framework stands on the `PEP20 (The Zen of Python) <https://www.python.org/dev/peps/pep-0020/>`_ principle:
*Dependency Injector* framework could be used in different application types:
.. code-block:: text
+ Web applications based on Flask, Django or any other web framework.
+ Asynchronous applications based on asyncio, Tornado and Twisted.
+ Standalone frameworks and libraries.
+ GUI applications.
Explicit is better than implicit
*Dependency Injector* framework could be integrated on different project
stages:
+ It could be used in the beginning of development of new applications.
+ It could be integrated into applications that are in active development
stage.
+ It could be used for refactoring of legacy applications.
Components of *Dependency Injector* framework could be used:
+ In composition with each other.
+ Separately between each other.
Main idea of *Dependency Injector* framework is to be useful tool for the
right thing.
You need to specify how to assemble and where to inject the dependencies explicitly.
The power of the framework is in its simplicity.
``Dependency Injector`` is a simple tool for the powerful concept.
.. disqus::

View File

@ -1,50 +0,0 @@
Structure of Dependency Injector
--------------------------------
.. meta::
:keywords: Python,DI,Dependency injection,IoC,Inversion of Control
:description: This article describes "Dependency Injector" framework
components and their interaction between each other.
Providers and containers are the former components of
the framework.
Current section describes *Dependency Injector* main entities and their
interaction between each other.
.. image:: /images/internals.png
:width: 100%
:align: center
There are 2 main entities: providers & containers.
Providers
~~~~~~~~~
Providers are strategies of accessing objects. For example,
:py:class:`dependency_injector.providers.Factory` creates new instance
of provided class every time it is called.
:py:class:`dependency_injector.providers.Singleton` creates provided
instance once and returns it on every next call. Base class is -
:py:class:`dependency_injector.providers.Provider`.
Providers could be:
+ Injected into each other.
+ Overridden by each other.
+ Extended.
Containers
~~~~~~~~~~
Containers are collections of providers. They are used for grouping
of providers by some principles. Base class is -
:py:class:`dependency_injector.containers.DeclarativeContainer`.
Containers could be:
+ Overridden by each other.
+ Copied from each other.
+ Extended.
.. disqus::

View File

@ -1,128 +0,0 @@
What is dependency injection and inversion of control?
------------------------------------------------------
.. meta::
:keywords: Python,DI,Dependency injection,IoC,Inversion of Control
:description: This article provides definition of dependency injection,
inversion of control and dependency inversion. It contains
example code in Python that is refactored to be following
inversion of control principle.
Definition
~~~~~~~~~~
Wikipedia provides quite good definitions of dependency injection pattern
and related principles:
.. glossary::
`Dependency injection`_
In software engineering, dependency injection is a software design
pattern that implements inversion of control for resolving
dependencies. A dependency is an object that can be used (a service).
An injection is the passing of a dependency to a dependent object (a
client) that would use it. The service is made part of the client's
state. Passing the service to the client, rather than allowing a
client to build or find the service, is the fundamental requirement of
the pattern.
Dependency injection allows a program design to follow the dependency
inversion principle. The client delegates to external code (the
injector) the responsibility of providing its dependencies. The client
is not allowed to call the injector code. It is the injecting code
that constructs the services and calls the client to inject them. This
means the client code does not need to know about the injecting code.
The client does not need to know how to construct the services. The
client does not need to know which actual services it is using. The
client only needs to know about the intrinsic interfaces of the
services because these define how the client may use the services.
This separates the responsibilities of use and construction.
`Inversion of control`_
In software engineering, inversion of control (IoC) describes a design
in which custom-written portions of a computer program receive the
flow of control from a generic, reusable library. A software
architecture with this design inverts control as compared to
traditional procedural programming: in traditional programming, the
custom code that expresses the purpose of the program calls into
reusable libraries to take care of generic tasks, but with inversion
of control, it is the reusable code that calls into the custom, or
task-specific, code.
Inversion of control is used to increase modularity of the program and
make it extensible, and has applications in object-oriented
programming and other programming paradigms. The term was popularized
by Robert C. Martin and Martin Fowler.
The term is related to, but different from, the dependency inversion
principle, which concerns itself with decoupling dependencies between
high-level and low-level layers through shared abstractions.
`Dependency inversion`_
In object-oriented programming, the dependency inversion principle
refers to a specific form of decoupling software modules. When
following this principle, the conventional dependency relationships
established from high-level, policy-setting modules to low-level,
dependency modules are reversed, thus rendering high-level modules
independent of the low-level module implementation details. The
principle states:
+ High-level modules should not depend on low-level modules.
Both should depend on abstractions.
+ Abstractions should not depend on details.
Details should depend on abstractions.
The principle inverts the way some people may think about
object-oriented design, dictating that both high- and low-level
objects must depend on the same abstraction.
Example
~~~~~~~
Let's go through the code of ``example.py``:
.. literalinclude:: ../../examples/di_demo/example.py
:language: python
:linenos:
At some point, things defined above mean, that the code from ``example.py``,
could look different, like in ``example_di.py``:
.. literalinclude:: ../../examples/di_demo/example_di.py
:language: python
:linenos:
Best explanation, ever
~~~~~~~~~~~~~~~~~~~~~~
Some times ago `user198313`_ posted awesome `question`_ about dependency
injection on `StackOverflow`_:
.. note::
How to explain dependency injection to a 5-year-old?
And `John Munsch`_ provided absolutely Great answer:
.. note::
When you go and get things out of the refrigerator for yourself, you can
cause problems. You might leave the door open, you might get something
Mommy or Daddy doesn't want you to have. You might even be looking for
something we don't even have or which has expired.
What you should be doing is stating a need, "I need something to drink
with lunch," and then we will make sure you have something when you sit
down to eat.
.. disqus::
.. _Dependency injection: http://en.wikipedia.org/wiki/Dependency_injection
.. _Inversion of control: https://en.wikipedia.org/wiki/Inversion_of_control
.. _Dependency inversion: https://en.wikipedia.org/wiki/Dependency_inversion_principle
.. _StackOverflow: http://stackoverflow.com/
.. _question: http://stackoverflow.com/questions/1638919/how-to-explain-dependency-injection-to-a-5-year-old/1639186
.. _user198313: http://stackoverflow.com/users/198313/user198313
.. _John Munsch: http://stackoverflow.com/users/31899/john-munsch

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,8 @@
Feedback
========
Feel free to post questions, bugs, feature requests, proposals etc. on
*Dependency Injector* GitHub Issues:
https://github.com/ets-labs/python-dependency-injector/issues
Your feedback is quite important!
To post a question, bug report, a feature proposal or get some help open a
`Github Issue <https://github.com/ets-labs/python-dependency-injector/issues>`_ or leave a comment
below.
.. disqus::

Some files were not shown because too many files have changed in this diff Show More