Skip to content

Instantly share code, notes, and snippets.

View fbraem's full-sized avatar

Franky Braem fbraem

View GitHub Profile
@melmi
melmi / fastapi-ioc-demo.py
Last active August 30, 2023 19:09
This a demo on how we can use an IoC container with FastAPI. Checkout my full article here: https://medium.com/@mohammad.elmi/how-to-use-fastapi-with-an-ioc-framework-f32c67d8c59b
import functools
from typing import Annotated, Any, Callable, Protocol, Type, TypeVar
from fastapi import APIRouter, Depends, FastAPI, Request
import punq
# domain - no dependency to FastAPI or IoC
class Greeter(Protocol):
def greet(self) -> str: ...