Dependency Injection Explained Like You’re 5 (with FastAPI Examples)

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 พ.ย. 2024

ความคิดเห็น • 28

  • @codingwithroby
    @codingwithroby  2 หลายเดือนก่อน +2

    There it is folks, dependency injection. What’s your biggest challenge as a developer right now?

  • @CodePythonPro
    @CodePythonPro 2 หลายเดือนก่อน

    Great video Eric, I hope to built videos like this soon (to help python community in Spanish), thanks for sharing your knowledge.

    • @codingwithroby
      @codingwithroby  2 หลายเดือนก่อน +1

      You can do it 🙂 Just be ready for a ton of work and a lot of trial and error.

  • @Wolfci
    @Wolfci 2 หลายเดือนก่อน

    More of these please lol just subbed great explanation

  • @danialmunsif
    @danialmunsif หลายเดือนก่อน +1

    well explained sir

  • @moinundin1221
    @moinundin1221 2 หลายเดือนก่อน +1

    easy concept for spring boot dev

    • @codingwithroby
      @codingwithroby  2 หลายเดือนก่อน +1

      Dependency injection is all over the place in Spring Boot!

  • @wait4015
    @wait4015 2 หลายเดือนก่อน

    Could you make a video on how to use dependency injection without fastapi?

    • @codingwithroby
      @codingwithroby  2 หลายเดือนก่อน

      Fairly similar - easy way is to initialize the object you will need in the class and then call directly.
      class FrameworkClass():
      def __init__(self, func):
      self.func = func
      def do_the_job(self):
      # some stuff
      self.func()
      def my_func():
      # do whatever here

  • @farazahmed1668
    @farazahmed1668 หลายเดือนก่อน +1

    which theme are you using in this tutorial?

    • @codingwithroby
      @codingwithroby  หลายเดือนก่อน

      On my VSCode?

    • @farazahmed1668
      @farazahmed1668 หลายเดือนก่อน

      @@codingwithroby yes the vs-code theme in this tutorial.
      And also i am very confused while learning fastapi there are so many ways in fastapi even doing a single thing like SQL alchemy vs sqlmodel and then using sa_column in sqlmodel to write SQL alchemy in sqlmodel and then there are so many drivers like psycopg3 vs psycopg2 vs asyncpg, and war does not stop there there are multiple sessions classes and multiple ways to use session like you can use it with context manager or with a context decorator. Every time I try to use async in python I get stuck. I thought django is complicated but in programming making a full stack application seems very complicated to me because one thing depends on the other and the other thing depends on something else. I am searching for a resource for learning fastapi like a django-book Django by Examples by antonio mele. Building real-world production grade projects.

  • @BritScientist
    @BritScientist 6 วันที่ผ่านมา

    Thank You. Why don't you organize you code in `__init__()` in your classes without creating unnecessary functions next to classes? Dependency injection in FastAPI requires callable, so it may be a class, not only function.

    • @codingwithroby
      @codingwithroby  6 วันที่ผ่านมา +1

      I have learned it is easy for beginners to learn by breaking things out like this. But perhaps in the future I should start implementing in the constructor or class like you are suggesting.

  • @krishnaagarwal7934
    @krishnaagarwal7934 2 หลายเดือนก่อน

    I love love love ur videoss❤❤❤

    • @codingwithroby
      @codingwithroby  2 หลายเดือนก่อน

      Aww thank you so much 😊

  • @ankitmoura1467
    @ankitmoura1467 2 หลายเดือนก่อน

    ok so whole point is to save resources and not create new instance on every api call ryt? but like when we create a new function which returns the new instance for us won't that fn be called on every api call and return a new instance i might be wrong but it feels like we r doing same thing with extra steps help?. also great content

    • @yashasmn245
      @yashasmn245 2 หลายเดือนก่อน

      Point was modular codebase, if you don't keep seperate function you would copy paste it every where .
      Makes easy to understand for everyone.

    • @codingwithroby
      @codingwithroby  หลายเดือนก่อน

      It's more for scalable and modular codebase, not resource management.

  • @aryaa4696
    @aryaa4696 8 วันที่ผ่านมา

    😱8 decade of experience 😅

    • @codingwithroby
      @codingwithroby  8 วันที่ผ่านมา

      "A decade of experience" 🙂

  • @shafiq_ramli
    @shafiq_ramli 2 หลายเดือนก่อน

    For once I thought DI is a security vulnerability like sqli 😅

  • @osogrande4999
    @osogrande4999 หลายเดือนก่อน

    Nonsense examples. None of those have any real world benefit or even meaning. The whole point of dependency injection in fastapi is to have your dependency function examine, extract or transform any part of the request, since your annotated dependency function arguments can specify parts of the request or the whole request object that fastapi will inject for you when invoking your dependency function, which itself can return a value to inject into your endpoint (or not). These examples literally have zero use in a fastapi endpoint and miss the point 100%.

    • @codingwithroby
      @codingwithroby  หลายเดือนก่อน

      I appreciate your feedback.