mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 09:57:37 +03:00 
			
		
		
		
	* 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
		
			
				
	
	
		
			28 lines
		
	
	
		
			469 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			469 B
		
	
	
	
		
			Python
		
	
	
	
	
	
"""Wiring string id example."""
 | 
						|
 | 
						|
import sys
 | 
						|
 | 
						|
from dependency_injector import containers, providers
 | 
						|
from dependency_injector.wiring import inject, Provide
 | 
						|
 | 
						|
 | 
						|
class Service:
 | 
						|
    ...
 | 
						|
 | 
						|
 | 
						|
class Container(containers.DeclarativeContainer):
 | 
						|
 | 
						|
    service = providers.Factory(Service)
 | 
						|
 | 
						|
 | 
						|
@inject
 | 
						|
def main(service: Service = Provide['service']) -> None:
 | 
						|
    ...
 | 
						|
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    container = Container()
 | 
						|
    container.wire(modules=[sys.modules[__name__]])
 | 
						|
 | 
						|
    main()
 |