injector
injector copied to clipboard
FastAPI support
Is there any way to use Injector library with FastAPI endpoints? The ideia would be to replace completely their Depends feature.
I've used fastapi-injector and it works fairly well. https://pypi.org/project/fastapi-injector/
Hey @Trinkes, sadly I can't say I know anything about this, I never had a chance to use FastAPI.
In general my answer would be that some custom integration would be required which usually boils down to:
- Implementing a custom Injector Scope
- Implementing some code that goes around and replaces all callables you want to inject into with something like https://github.com/python-injector/flask_injector/blob/004b9b52727e9699d23168a600c490ee5de7a395/flask_injector/init.py#L86 so that whenever they're called the dependency injection happens transparently and extra parameters are provided
Sadly no good how-to guide explaining that.
@jack-michaud mentioned an interesting integration project which I didn't know about – thank you – maybe that'll help you