.. _fastdepends-example: FastDepends example =================== .. meta:: :keywords: Python,Dependency Injection,FastDepends,Example :description: This example demonstrates a usage of the FastDepends and Dependency Injector. This example shows how to use ``Dependency Injector`` with `FastDepends `_. Example code is available on `Github `_. Quick sample ------------ Just use it within ``Depends`` .. code-block:: python import sys from dependency_injector import containers, providers from dependency_injector.wiring import inject, Provide from fast_depends import Depends class CoefficientService: @staticmethod def get_coefficient() -> float: return 1.2 class Container(containers.DeclarativeContainer): service = providers.Factory(CoefficientService) @inject def apply_coefficient( a: int, coefficient_provider: CoefficientService = Depends(Provide[Container.service]), ) -> float: return a * coefficient_provider.get_coefficient() container = Container() container.wire(modules=[sys.modules[__name__]]) apply_coefficient(100) == 120.0