mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 09:57:37 +03:00 
			
		
		
		
	* Add implementation and tests * Refactor dependency provider docs * Update docs * Update changelog
		
			
				
	
	
		
			26 lines
		
	
	
		
			486 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			486 B
		
	
	
	
		
			Python
		
	
	
	
	
	
"""`Dependency` provider default example."""
 | 
						|
 | 
						|
import abc
 | 
						|
 | 
						|
from dependency_injector import containers, providers
 | 
						|
 | 
						|
 | 
						|
class Cache(metaclass=abc.ABCMeta):
 | 
						|
    ...
 | 
						|
 | 
						|
 | 
						|
class InMemoryCache(Cache):
 | 
						|
    ...
 | 
						|
 | 
						|
 | 
						|
class Container(containers.DeclarativeContainer):
 | 
						|
 | 
						|
    cache = providers.Dependency(instance_of=Cache, default=InMemoryCache())
 | 
						|
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    container = Container()
 | 
						|
    cache = container.cache()  # provides InMemoryCache()
 | 
						|
 | 
						|
    assert isinstance(cache, InMemoryCache)
 |