{"id":18068425,"url":"https://github.com/lexxai/fastapi_depends","last_synced_at":"2026-04-08T18:06:57.642Z","repository":{"id":258847922,"uuid":"874828246","full_name":"lexxai/FastAPI_Depends","owner":"lexxai","description":"FastAPI Dependency Injection: 21 Examples Using Depends() with AI Answers ","archived":false,"fork":false,"pushed_at":"2024-10-22T19:17:26.000Z","size":107,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T16:13:05.634Z","etag":null,"topics":["ai","dependency-injection","docker","fastapi","patterns","postgresql","python","redis","singleton","sql","sqlalchemy"],"latest_commit_sha":null,"homepage":"https://lexxai.blogspot.com/2024/10/fastapi-dependency-injection-21.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lexxai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-18T14:33:33.000Z","updated_at":"2024-10-20T22:27:09.000Z","dependencies_parsed_at":"2024-12-18T22:50:29.117Z","dependency_job_id":null,"html_url":"https://github.com/lexxai/FastAPI_Depends","commit_stats":null,"previous_names":["lexxai/fastapi_depends"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexxai%2FFastAPI_Depends","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexxai%2FFastAPI_Depends/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexxai%2FFastAPI_Depends/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexxai%2FFastAPI_Depends/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lexxai","download_url":"https://codeload.github.com/lexxai/FastAPI_Depends/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361699,"owners_count":20926643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","dependency-injection","docker","fastapi","patterns","postgresql","python","redis","singleton","sql","sqlalchemy"],"created_at":"2024-10-31T08:06:25.867Z","updated_at":"2025-12-30T21:40:02.379Z","avatar_url":"https://github.com/lexxai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI Dependency Injection: 21 Examples Using Depends() with AI Answers\n\n## Why ?\nOnce I wanted to understand how Depends works in FastAPI more thoroughly to understand what's under the hood. I started communicating with the AI. The answer was a question, and I got hooked. \n\nI decided to test it in real code and created a training project and wrote this post for it based on my questions to the AI and its answers.\n\nSome answers were wrong, some I had already optimized a bit. But all the results shown are real and created by me personally. \n\nThe result was 21 training examples written in Python, where I checked the answers and suggestions from the AI.\n\n\nFull publication:\nhttps://lexxai.blogspot.com/2024/10/fastapi-dependency-injection-21.html\n\nDeployed version:\nhttps://fastapi-depends.onrender.com/docs\n\nQuestions: \n- Prepare for use FastAPI project\n- How does injection Depends work in FastAPI?\n- The decision of who will run when depends on the finish route. The question is, will the yield continue?\n- But the response was wrong!! We were expecting the output  \"Cleaning up the resource\" after the error.\n- So the dependency function must always be used with a try: finally?\n- Okay, if depends is a class, then its instance is created once, like a singleton? How can information be saved between requests if the instance is dead after the request?\n- In the redis example, should the database initialization ideally also be in the form of dependencies?\n- With the asynchronous yeld for the asynchronous database initialization, is there a lot of complexity involved? \n\n![зображення](https://github.com/user-attachments/assets/4c967767-c692-4baf-8294-a8ef5eb9a234)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexxai%2Ffastapi_depends","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flexxai%2Ffastapi_depends","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexxai%2Ffastapi_depends/lists"}