mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 01:47:36 +03:00 
			
		
		
		
	Update resource docs
This commit is contained in:
		
							parent
							
								
									9a43ee7e88
								
							
						
					
					
						commit
						d8bb4a3bd8
					
				| 
						 | 
					@ -98,7 +98,7 @@ you configure global resource:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
       configure_logging = providers.Resource(
 | 
					       configure_logging = providers.Resource(
 | 
				
			||||||
           logging.config.fileConfig,
 | 
					           logging.config.fileConfig,
 | 
				
			||||||
           fname='logging.ini',
 | 
					           fname="logging.ini",
 | 
				
			||||||
       )
 | 
					       )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Function initializer does not provide a way to specify custom resource shutdown.
 | 
					Function initializer does not provide a way to specify custom resource shutdown.
 | 
				
			||||||
| 
						 | 
					@ -210,8 +210,8 @@ first argument.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. _resource-provider-wiring-closing:
 | 
					.. _resource-provider-wiring-closing:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Resources, wiring and per-function execution scope
 | 
					Resources, wiring, and per-function execution scope
 | 
				
			||||||
--------------------------------------------------
 | 
					---------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can compound ``Resource`` provider with :ref:`wiring` to implement per-function
 | 
					You can compound ``Resource`` provider with :ref:`wiring` to implement per-function
 | 
				
			||||||
execution scope. For doing this you need to use additional ``Closing`` marker from
 | 
					execution scope. For doing this you need to use additional ``Closing`` marker from
 | 
				
			||||||
| 
						 | 
					@ -220,7 +220,7 @@ execution scope. For doing this you need to use additional ``Closing`` marker fr
 | 
				
			||||||
.. literalinclude:: ../../examples/wiring/flask_resource_closing.py
 | 
					.. literalinclude:: ../../examples/wiring/flask_resource_closing.py
 | 
				
			||||||
   :language: python
 | 
					   :language: python
 | 
				
			||||||
   :lines: 3-
 | 
					   :lines: 3-
 | 
				
			||||||
   :emphasize-lines: 24
 | 
					   :emphasize-lines: 22
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Framework initializes and injects the resource into the function. With the ``Closing`` marker
 | 
					Framework initializes and injects the resource into the function. With the ``Closing`` marker
 | 
				
			||||||
framework calls resource ``shutdown()`` method when function execution is over.
 | 
					framework calls resource ``shutdown()`` method when function execution is over.
 | 
				
			||||||
| 
						 | 
					@ -325,7 +325,7 @@ When you use resource provider with asynchronous initializer you need to call it
 | 
				
			||||||
       connection = await container.connection.shutdown()
 | 
					       connection = await container.connection.shutdown()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if __name__ == '__main__':
 | 
					   if __name__ == "__main__":
 | 
				
			||||||
       asyncio.run(main())
 | 
					       asyncio.run(main())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Container ``init_resources()`` and ``shutdown_resources()`` methods should be used asynchronously if there is
 | 
					Container ``init_resources()`` and ``shutdown_resources()`` methods should be used asynchronously if there is
 | 
				
			||||||
| 
						 | 
					@ -349,7 +349,7 @@ at least one asynchronous resource provider:
 | 
				
			||||||
       await container.shutdown_resources()
 | 
					       await container.shutdown_resources()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   if __name__ == '__main__':
 | 
					   if __name__ == "__main__":
 | 
				
			||||||
       asyncio.run(main())
 | 
					       asyncio.run(main())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
See also:
 | 
					See also:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,12 +29,12 @@ class Container(containers.DeclarativeContainer):
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    container = Container(config={'max_workers': 4})
 | 
					    container = Container(config={"max_workers": 4})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    container.init_resources()
 | 
					    container.init_resources()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    logging.info('Resources are initialized')
 | 
					    logging.info("Resources are initialized")
 | 
				
			||||||
    thread_pool = container.thread_pool()
 | 
					    thread_pool = container.thread_pool()
 | 
				
			||||||
    thread_pool.map(print, range(10))
 | 
					    thread_pool.map(print, range(10))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user