mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-10-31 16:07:51 +03:00 
			
		
		
		
	Update object provider docs
This commit is contained in:
		
							parent
							
								
									9969bc4761
								
							
						
					
					
						commit
						486353bbea
					
				|  | @ -29,7 +29,7 @@ be thread safe. | ||||||
|     factory |     factory | ||||||
|     singleton |     singleton | ||||||
|     callable |     callable | ||||||
|  |     object | ||||||
|     external_dependency |     external_dependency | ||||||
|     static |  | ||||||
|     overriding |     overriding | ||||||
|     custom |     custom | ||||||
|  |  | ||||||
							
								
								
									
										12
									
								
								docs/providers/object.rst
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								docs/providers/object.rst
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | ||||||
|  | Object providers | ||||||
|  | ---------------- | ||||||
|  | 
 | ||||||
|  | .. currentmodule:: dependency_injector.providers | ||||||
|  | 
 | ||||||
|  | :py:class:`Object` provider returns provided instance "as is" | ||||||
|  | 
 | ||||||
|  | Example: | ||||||
|  | 
 | ||||||
|  | .. literalinclude:: ../../examples/providers/object.py | ||||||
|  |    :language: python | ||||||
|  |    :linenos: | ||||||
|  | @ -1,22 +0,0 @@ | ||||||
| Static providers |  | ||||||
| ---------------- |  | ||||||
| 
 |  | ||||||
| .. currentmodule:: dependency_injector.providers |  | ||||||
| 
 |  | ||||||
| Static providers are family of providers that return their values "as is". |  | ||||||
| There are four types of static providers: |  | ||||||
| 
 |  | ||||||
|     - :py:class:`Class` |  | ||||||
|     - :py:class:`Object` |  | ||||||
|     - :py:class:`Function` |  | ||||||
|     - :py:class:`Value` |  | ||||||
| 
 |  | ||||||
| All of them have the same behaviour (inherited from  |  | ||||||
| :py:class:`StaticProvider`), but usage of any is predicted by readability  |  | ||||||
| and providing object's type. |  | ||||||
| 
 |  | ||||||
| Example: |  | ||||||
| 
 |  | ||||||
| .. literalinclude:: ../../examples/providers/static.py |  | ||||||
|    :language: python |  | ||||||
|    :linenos: |  | ||||||
							
								
								
									
										10
									
								
								examples/providers/object.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								examples/providers/object.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | ||||||
|  | """Object providers example.""" | ||||||
|  | 
 | ||||||
|  | import dependency_injector.providers as providers | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | # Creating object provider: | ||||||
|  | object_provider = providers.Object(1) | ||||||
|  | 
 | ||||||
|  | # Making some asserts: | ||||||
|  | assert object_provider() == 1 | ||||||
|  | @ -1,20 +0,0 @@ | ||||||
| """Static providers example.""" |  | ||||||
| 
 |  | ||||||
| import dependency_injector.providers as providers |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| # Provides class - `object`: |  | ||||||
| cls_provider = providers.Class(object) |  | ||||||
| assert cls_provider() is object |  | ||||||
| 
 |  | ||||||
| # Provides object - `object()`: |  | ||||||
| object_provider = providers.Object(object()) |  | ||||||
| assert isinstance(object_provider(), object) |  | ||||||
| 
 |  | ||||||
| # Provides function - `len`: |  | ||||||
| function_provider = providers.Function(len) |  | ||||||
| assert function_provider() is len |  | ||||||
| 
 |  | ||||||
| # Provides value - `123`: |  | ||||||
| value_provider = providers.Value(123) |  | ||||||
| assert value_provider() == 123 |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user