mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 01:47:36 +03:00 
			
		
		
		
	* 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
		
			
				
	
	
		
			75 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			ReStructuredText
		
	
	
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			ReStructuredText
		
	
	
	
	
	
Bundles mini application example
 | 
						|
--------------------------------
 | 
						|
 | 
						|
.. currentmodule:: dependency_injector.containers
 | 
						|
 | 
						|
"Bundles" is an example mini application that is intended 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 ``bundles/users/__init__.py``:
 | 
						|
 | 
						|
.. literalinclude:: ../../examples/miniapps/bundles/bundles/users/__init__.py
 | 
						|
   :language: python
 | 
						|
 | 
						|
.. note::
 | 
						|
 | 
						|
    - ``Users`` container has dependency on database.
 | 
						|
 | 
						|
Listing of ``bundles/photos/__init__.py``:
 | 
						|
 | 
						|
.. literalinclude:: ../../examples/miniapps/bundles/bundles/photos/__init__.py
 | 
						|
   :language: python
 | 
						|
 | 
						|
.. 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
 | 
						|
 | 
						|
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::
 |