mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-01 00:17:55 +03:00 
			
		
		
		
	* Update application-single-container example * Update application-multiple-containers example * Update decoupled-packages example * Update movie lister example * Update CLI tutorial * Update sanic example * Update sanic example with wiring_config * Update fastapi example * Update fastapi-simple example * Update fastapi-sqlalchemy example * Update flask-blueprints example * Update flask example and tutorial * Update aiohttp example and tutorial * Update asyncio-daemon example and tutorial
		
			
				
	
	
		
			81 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| """Containers module."""
 | |
| 
 | |
| import logging.config
 | |
| import sqlite3
 | |
| 
 | |
| import boto3
 | |
| from dependency_injector import containers, providers
 | |
| 
 | |
| from . import services
 | |
| 
 | |
| 
 | |
| class Core(containers.DeclarativeContainer):
 | |
| 
 | |
|     config = providers.Configuration()
 | |
| 
 | |
|     logging = providers.Resource(
 | |
|         logging.config.dictConfig,
 | |
|         config=config.logging,
 | |
|     )
 | |
| 
 | |
| 
 | |
| class Gateways(containers.DeclarativeContainer):
 | |
| 
 | |
|     config = providers.Configuration()
 | |
| 
 | |
|     database_client = providers.Singleton(
 | |
|         sqlite3.connect,
 | |
|         config.database.dsn,
 | |
|     )
 | |
| 
 | |
|     s3_client = providers.Singleton(
 | |
|         boto3.client,
 | |
|         service_name="s3",
 | |
|         aws_access_key_id=config.aws.access_key_id,
 | |
|         aws_secret_access_key=config.aws.secret_access_key,
 | |
|     )
 | |
| 
 | |
| 
 | |
| class Services(containers.DeclarativeContainer):
 | |
| 
 | |
|     config = providers.Configuration()
 | |
|     gateways = providers.DependenciesContainer()
 | |
| 
 | |
|     user = providers.Factory(
 | |
|         services.UserService,
 | |
|         db=gateways.database_client,
 | |
|     )
 | |
| 
 | |
|     auth = providers.Factory(
 | |
|         services.AuthService,
 | |
|         db=gateways.database_client,
 | |
|         token_ttl=config.auth.token_ttl.as_int(),
 | |
|     )
 | |
| 
 | |
|     photo = providers.Factory(
 | |
|         services.PhotoService,
 | |
|         db=gateways.database_client,
 | |
|         s3=gateways.s3_client,
 | |
|     )
 | |
| 
 | |
| 
 | |
| class Application(containers.DeclarativeContainer):
 | |
| 
 | |
|     config = providers.Configuration(yaml_files=["config.yml"])
 | |
| 
 | |
|     core = providers.Container(
 | |
|         Core,
 | |
|         config=config.core,
 | |
|     )
 | |
| 
 | |
|     gateways = providers.Container(
 | |
|         Gateways,
 | |
|         config=config.gateways,
 | |
|     )
 | |
| 
 | |
|     services = providers.Container(
 | |
|         Services,
 | |
|         config=config.services,
 | |
|         gateways=gateways,
 | |
|     )
 |