Why Every .NET Developer NEEDS Dependency Injection

Поділитися
Вставка
  • Опубліковано 9 жов 2024

КОМЕНТАРІ • 18

  • @Sivet555
    @Sivet555 2 дні тому +14

    The only thing I feel like this explanation needs is, what if I want to have both an Orc and a Goblin enemy at the same time?
    Besides that it is a great intro to Dependency Injection. But I feel like this is what most dependency injection intro's forget about. It is nice to be able to swap out which service is used in compile time.
    But with interfaces often you want to decide this during runtime no?

    • @PatrickGod
      @PatrickGod  День тому +6

      Thanks so much for the feedback! You’re totally right. It’s not just about swapping services at compile time. If you want both an Orc and a Goblin at the same time, you'd need a way to handle that at runtime, like using a factory. I might dive deeper into this in a follow-up video. Appreciate you pointing it out!

    • @robadobdob
      @robadobdob 16 годин тому

      I think that’s where the new Keyed services comes in. You can register both with a different key and then select at runtime by key.

  • @byejason
    @byejason День тому +5

    So this serves as a simple explanation of DI including a basic demonstration, but i'm not sure it actually explains why you would want to. Use of a REST API in the demonstration confuses things somewhat as you would expect methods on an EnemyController to receive an IEnemy on which to act rather than having one injected on controller construction. I know it was only used as an easy way to demonstrate the concept but I feel like is raises more questions than it answers.

    • @jimiscott
      @jimiscott День тому

      Usaully love Patrick's videos but I agree with you on this one. The example needs to be a deeper and I think cover an actual requirement vs. some made up RPG cruft.

    • @ErazerPT
      @ErazerPT 7 годин тому +1

      Pretty much. Makes the whole thing clear as mud because it got lost in the sauce. As a DI example, this would have gone into a Factory pattern that would then be used by "whatever you're doing", but instead it got thrown into the .Net API internals and it becomes "what are we talking about"? A better example would be a controller that got a "creature type", goes into a factory and gets an IEnemy for that type. And then have something like "Difficulty [Easy|Normal|Hard]" as a service injection. Now the controller can return enemy.Attack()*Difficulty(). Voila, everything is injected and the example makes sense...

  • @buluf
    @buluf 2 дні тому +8

    But in this case why would i want have goblin and orc at the same scope of project? because to use one i need to register and unregister the other

    • @NoName-1337
      @NoName-1337 День тому

      Idk. Maybe to switch datasources or different logic to calculate something for different countries because of different rules and laws. But yes, I do not got the point either.

  • @bhaveshpanchariya5575
    @bhaveshpanchariya5575 17 годин тому

    Hi patrick,
    Can you make one video on Iqueryable and Ienumarable.?

  • @weeakz4815
    @weeakz4815 22 години тому

    Hey Patrick, i applied for your job. Your description says I should contact you here.

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd 23 години тому

    thank you so much

  • @JohnsonVfx
    @JohnsonVfx День тому

    Hey are you looking for a Video Editor?

  • @airixxxx
    @airixxxx 18 хвилин тому

    I feel the explanation is great but the payoff at the end falls flat, I've seen this with a lot of tutorials, at the end it's not clear how this will be used.

  • @shadab-8
    @shadab-8 2 дні тому +2

    Great explanation

    • @PatrickGod
      @PatrickGod  2 дні тому

      Glad you think so! Thanks a lot for your feedback!