Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract dependency injection system to a separate Python package #2967

Closed
dmtrs opened this issue Mar 20, 2021 · 2 comments
Closed

Extract dependency injection system to a separate Python package #2967

dmtrs opened this issue Mar 20, 2021 · 2 comments

Comments

@dmtrs
Copy link

dmtrs commented Mar 20, 2021

Description / Idea

I started working with fastapi and found the Dependency Injection system really elegant and useful. Now, I wish I could use it in other projects that do not involve a fastapi dependency.

My idea is to make the dependency injection as a separate python package that fastapi would include.

Example

import asyncio

from depends import inject, Depends

async def get_something() -> str:
    return 'test'

@inject
async def main(text: str = Depends(get_something())):
    print(text)

The solution you would like

I can understand this not being a priority or motive for the community of the fastapi, but wanted to get some feedback on this. Please feel free to close the request.

@dmtrs dmtrs added the feature New feature or request label Mar 20, 2021
@tiangolo
Copy link
Member

Thank you! The thing is that the main point of the dependency injection system in FastAPI is to be integrated with FastAPI, to extract the data from requests and integrate that with OpenAPI.

So I'm not sure what would be the right way to put this on an external package.

Nevertheless, @adriangb created https://github.com/adriangb/di, I haven't been able to study and play with it yet, but I suspect it's probably right what you need (I also have to review some proposals he was making to change the dependency injection system in FastAPI, hopefully, I'll be able to get to that soon). 🤓

Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I'm checking each one in order.

@dmtrs
Copy link
Author

dmtrs commented Nov 27, 2022

Hey @tiangolo, thanks for coming back to this 🙏🏼

I was able to go through FastAPI code and extract parts of the code. Not production ready but you can see here: https://github.com/dmtrs/dependable

@github-actions github-actions bot removed the answered label Nov 27, 2022
@tiangolo tiangolo added question Question or problem reviewed question-migrate and removed feature New feature or request labels Feb 24, 2023
@fastapi fastapi locked and limited conversation to collaborators Feb 28, 2023
@tiangolo tiangolo converted this issue into discussion #9024 Feb 28, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants