mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 01:47:36 +03:00 
			
		
		
		
	Changing docs structure, move .rst docs out from root
This commit is contained in:
		
							parent
							
								
									d2ec7fbe45
								
							
						
					
					
						commit
						7f82c89d95
					
				| 
						 | 
					@ -1,38 +0,0 @@
 | 
				
			||||||
Advanced usage
 | 
					 | 
				
			||||||
==============
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Below you can find some variants of advanced usage of *Objects*.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@inject decorator
 | 
					 | 
				
			||||||
-----------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
``@inject`` decorator could be used for patching any callable with injection.
 | 
					 | 
				
			||||||
Any Python object will be injected *as is*, except *Objects* providers,
 | 
					 | 
				
			||||||
that will be called to provide injectable value.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.. code-block:: python
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    """`@inject` decorator example."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    from objects.providers import NewInstance
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    from objects.injections import KwArg
 | 
					 | 
				
			||||||
    from objects.injections import inject
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    new_object = NewInstance(object)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @inject(KwArg('object_a', new_object))
 | 
					 | 
				
			||||||
    @inject(KwArg('some_setting', 1334))
 | 
					 | 
				
			||||||
    def example_callback(object_a, some_setting):
 | 
					 | 
				
			||||||
        """This function has dependencies on object a and b.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Dependencies are injected using `@inject` decorator.
 | 
					 | 
				
			||||||
        """
 | 
					 | 
				
			||||||
        assert isinstance(object_a, object)
 | 
					 | 
				
			||||||
        assert some_setting == 1334
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    example_callback()
 | 
					 | 
				
			||||||
    example_callback()
 | 
					 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,7 @@ Example:
 | 
				
			||||||
    :width: 100%
 | 
					    :width: 100%
 | 
				
			||||||
    :align: center
 | 
					    :align: center
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. literalinclude:: ../examples/catalogs/simple.py
 | 
					.. literalinclude:: ../../examples/catalogs/simple.py
 | 
				
			||||||
   :language: python
 | 
					   :language: python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Operating with catalog providers
 | 
					Operating with catalog providers
 | 
				
			||||||
| 
						 | 
					@ -59,7 +59,7 @@ providers:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Example:
 | 
					Example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. literalinclude:: ../examples/catalogs/operating_with_providers.py
 | 
					.. literalinclude:: ../../examples/catalogs/operating_with_providers.py
 | 
				
			||||||
   :language: python
 | 
					   :language: python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Overriding of catalogs
 | 
					Overriding of catalogs
 | 
				
			||||||
| 
						 | 
					@ -76,10 +76,10 @@ There are two ways to override catalog by another catalog:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Example of overriding catalog using ``Catalog.override()`` method:
 | 
					Example of overriding catalog using ``Catalog.override()`` method:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. literalinclude:: ../examples/catalogs/override.py
 | 
					.. literalinclude:: ../../examples/catalogs/override.py
 | 
				
			||||||
   :language: python
 | 
					   :language: python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Example of overriding catalog using ``@override()`` decorator:
 | 
					Example of overriding catalog using ``@override()`` decorator:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. literalinclude:: ../examples/catalogs/override_decorator.py
 | 
					.. literalinclude:: ../../examples/catalogs/override_decorator.py
 | 
				
			||||||
   :language: python
 | 
					   :language: python
 | 
				
			||||||
| 
						 | 
					@ -1,46 +0,0 @@
 | 
				
			||||||
Inline injections
 | 
					 | 
				
			||||||
=================
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@inject decorator
 | 
					 | 
				
			||||||
-----------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
``@inject`` decorator can be used for making *inline* dependency injections.
 | 
					 | 
				
			||||||
It *patches* decorated callable in such way that dependency injection will be
 | 
					 | 
				
			||||||
done before every call of decorated callable.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
``@inject`` decorator takes only argument that is supposed to be an
 | 
					 | 
				
			||||||
``objects.injections.Injection`` instance.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Any Python object will be injected *as is*, except *Objects* providers,
 | 
					 | 
				
			||||||
that will be called to provide injectable value.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Below is an example of how Flask's view could be patched using ``@inject``
 | 
					 | 
				
			||||||
decorator:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.. code-block:: python
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    """`@inject` decorator example."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    from objects.providers import NewInstance
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    from objects.injections import KwArg
 | 
					 | 
				
			||||||
    from objects.injections import inject
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    new_object = NewInstance(object)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @inject(KwArg('object_a', new_object))
 | 
					 | 
				
			||||||
    @inject(KwArg('some_setting', 1334))
 | 
					 | 
				
			||||||
    def example_callback(object_a, some_setting):
 | 
					 | 
				
			||||||
        """This function has dependencies on object a and b.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Dependencies are injected using `@inject` decorator.
 | 
					 | 
				
			||||||
        """
 | 
					 | 
				
			||||||
        assert isinstance(object_a, object)
 | 
					 | 
				
			||||||
        assert some_setting == 1334
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    example_callback()
 | 
					 | 
				
			||||||
    example_callback()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					@ -35,10 +35,10 @@ Contents
 | 
				
			||||||
..  toctree::
 | 
					..  toctree::
 | 
				
			||||||
    :maxdepth: 2
 | 
					    :maxdepth: 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    introduction
 | 
					    main/introduction
 | 
				
			||||||
    installation
 | 
					    main/installation
 | 
				
			||||||
    providers/index
 | 
					    providers/index
 | 
				
			||||||
    catalogs
 | 
					    catalogs/index
 | 
				
			||||||
    decorators
 | 
					    advanced_usage/index
 | 
				
			||||||
    feedback
 | 
					    main/feedback
 | 
				
			||||||
    changelog
 | 
					    main/changelog
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user