mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-10-31 16:07:51 +03:00 
			
		
		
		
	Add docs and example
This commit is contained in:
		
							parent
							
								
									3a4d84787e
								
							
						
					
					
						commit
						b5ceea9402
					
				|  | @ -306,6 +306,25 @@ configuration provider to strict mode. | ||||||
| 
 | 
 | ||||||
|    Modifier ``.required()`` should be specified before type modifier ``.as_*()``. |    Modifier ``.required()`` should be specified before type modifier ``.as_*()``. | ||||||
| 
 | 
 | ||||||
|  | Aliases | ||||||
|  | ------- | ||||||
|  | 
 | ||||||
|  | You can use ``Configuration`` provider with a context manager to create aliases. | ||||||
|  | 
 | ||||||
|  | .. literalinclude:: ../../examples/providers/configuration/configuration_alias.py | ||||||
|  |    :language: python | ||||||
|  |    :lines: 3- | ||||||
|  |    :emphasize-lines: 14,22 | ||||||
|  | 
 | ||||||
|  | .. note:: | ||||||
|  | 
 | ||||||
|  |    Library ``environs`` is a 3rd party library. You need to install it | ||||||
|  |    separately:: | ||||||
|  | 
 | ||||||
|  |       pip install environs | ||||||
|  | 
 | ||||||
|  |    Documentation is available on GitHub: https://github.com/sloria/environs | ||||||
|  | 
 | ||||||
| Injecting invariants | Injecting invariants | ||||||
| -------------------- | -------------------- | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										36
									
								
								examples/providers/configuration/configuration_alias.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								examples/providers/configuration/configuration_alias.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,36 @@ | ||||||
|  | """`Configuration` provider alias example.""" | ||||||
|  | 
 | ||||||
|  | from dependency_injector import containers, providers | ||||||
|  | from environs import Env | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Container(containers.DeclarativeContainer): | ||||||
|  | 
 | ||||||
|  |     config = providers.Configuration() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | if __name__ == '__main__': | ||||||
|  |     env = Env() | ||||||
|  |     container = Container() | ||||||
|  | 
 | ||||||
|  |     with container.config.some_plugin_name as plugin: | ||||||
|  |         plugin.some_interval_ms.override( | ||||||
|  |             env.int( | ||||||
|  |                 'SOME_INTERVAL_MS', | ||||||
|  |                 default=30000, | ||||||
|  |             ), | ||||||
|  |         ) | ||||||
|  | 
 | ||||||
|  |         with plugin.kafka as kafka: | ||||||
|  |             kafka.bootstrap_servers.override( | ||||||
|  |                 env.list( | ||||||
|  |                     'KAFKA_BOOTSTRAP_SERVERS', | ||||||
|  |                     default=['kafka1', 'kafka2'], | ||||||
|  |                 ), | ||||||
|  |             ) | ||||||
|  |             kafka.security_protocol.override( | ||||||
|  |                 env.str( | ||||||
|  |                     'KAFKA_SECURITY_PROTOCOL', | ||||||
|  |                     default='SASL_SSL', | ||||||
|  |                 ), | ||||||
|  |             ) | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user