Injectable - Flutter & Dart Equivalent to Dagger & Angular Dependency Injection

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

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

  • @matiasosuna6812
    @matiasosuna6812 3 ปีที่แล้ว +24

    Reso! Could you update this tutorial?
    Like this for him to see it

  • @deoneloff
    @deoneloff 4 ปีที่แล้ว +3

    Very nice! This makes a huge difference to me. Thanks a lot, once again, for a most valuable Flutter training session!!

  • @psybitcoin
    @psybitcoin 4 ปีที่แล้ว +4

    Love it! WOuld also love to see you working with Firebase in Flutter

  • @focaapp516
    @focaapp516 4 ปีที่แล้ว +1

    Man I really admire your work, I wish to help people learning flutter like you do, but time is a really valuable resources that I will I had more. Even then you save me a lot of money finding this awesome libs.

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

    are u magician ? this was great content , thank you

  • @andres-rodriguez
    @andres-rodriguez 4 ปีที่แล้ว

    15:07, thank you it made sense. But I tried removing line 15 and 16, and everything still ran. Those two lines are redundant in my opinion. But I made sure to include CounterChangeNotifier dependency right below. I am so happy you share your knowledge and I learn a lot from you!

  • @evandrobarbosadosreis
    @evandrobarbosadosreis 4 ปีที่แล้ว

    That's exactly what I was looking for. Greeting from Brazil.

  • @khanaa13
    @khanaa13 4 ปีที่แล้ว +3

    This package and tutorial is absolutely mindblowing! 🔥
    How would you register sharedPreferences with this seeing as how you normally do
    final sharedPreferences = await SharedPreferences.getInstance();
    getIt.registerLazySingleton(() => sharedPreferences);
    Injectable does not allow you to specify third party classes as being injectable
    Right now I'm resorting to creating a separate file for ones that have custom ways of setting up their instances, mimicking the style of the generated file but doing the injection manually and then calling this custom function in main.dart too

    • @ThalesFrigo
      @ThalesFrigo 4 ปีที่แล้ว

      Good question

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว

      Exactly what I found. This is the very first release of injectable so it has some loose ends, unfortunately.

    • @BrysonThill
      @BrysonThill 4 ปีที่แล้ว

      One alternative is to write a wrapper class around SharedPreferences and make that @injectable.

    • @khanaa13
      @khanaa13 4 ปีที่แล้ว

      @@BrysonThill Yes that's what I said

    • @BrysonThill
      @BrysonThill 4 ปีที่แล้ว

      @@khanaa13 I think we're talking about different things. You said you manually did the GetIt configuration for these third party classes and called another function from main.
      The alternative I proposed is to create a new class like InjectableSharedPreferences that wraps SharedPreferences, which you can annotate using @injectable and not use two separate code paths for your configuration.

  • @CarlosHernandez-dv1ib
    @CarlosHernandez-dv1ib 3 ปีที่แล้ว

    man i had to watch like ten times this video, now i understood, thanks so much!!

  • @reprevise
    @reprevise 4 ปีที่แล้ว +3

    Can you make a video on the difference between factory, singleton, and lazy singletons and when to use them?

    • @bogdanb904
      @bogdanb904 4 ปีที่แล้ว +4

      First, let me tell you what a singleton is. A singleton class ( whether you call it a service, repo, etc. ) is a class that gets instanced only ONCE for the whole application's lifetime. It usually has a private constructor, so you cannot create an instance of that class by yourself. A singleton gets gets instanced when the application is started. A lazy singleton is instanced only when it is first demanded. Now, factories can also be called 'instance-per-request'. Whenever you need that class, it gets instanced. As far as example goes, think of a service that holds the current theme of your application ( e.g dark / light ). You would want that to be a Singleton, since you want to have the same theme state in any of your screens.

  • @aytunch
    @aytunch 4 ปีที่แล้ว +1

    Hi Matej, can you briefly explain at exactly which scenarios we usually need the use of a Singleton/D.Injection/ServiceLocators that you show in this tutorial? I guess database provider is one of them. Other than that, if we are using Bloc or provider, why do we need to use these strategies? You stated for not having spaghetti code. Is that the only advantage? For a production quality app, what parts/modules need to take advantage of these strategies? Thanks. I hope you can make a tutorial for this very question: explaining when to use these solutions. Thanks man

  • @jimaustin3608
    @jimaustin3608 3 ปีที่แล้ว

    Both ‘follow-along’ code and master show build_runner fail; looks like a null-safety problem caused by the newer null-safety relaeases.
    Failed to precompile build_runner:build_runner:
    /c:/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.7.3/bin/build_runner.dart:87:9: Warning: Operand of null-aware operation '?.' has type 'StreamSubscription' which excludes null.

  • @codersplayground4391
    @codersplayground4391 2 ปีที่แล้ว

    The abstract class annotation must always be equal to the annotation of the implementation class ?

  • @MrARBN
    @MrARBN 4 ปีที่แล้ว

    Hey again. And thanks sharing this experience. Im an android fan so i really like native programming, but in few weeks ago im going to instrest to flutter. Im your huge fan, believe me. Your kotlin toturials really helping me out there, now i want to start your flutter toturials. So i hope you tell me a time line to watch theme. Which one is for beginners like me and show me the steps to learn it. By the way. I steel hope you get back to kotlin 😊😊😊. Thank you and see you around.

  • @silverqui.9698
    @silverqui.9698 4 ปีที่แล้ว

    Hi Im dealing with something and maybe you can help me, how do you inject SharedPreferences ?
    I tryed the example given by injectable documentation
    @registerModule
    abstract class RegisterModule {
    @preResolve
    Future get prefs => SharedPreferences.getInstance();
    }
    but is not working,
    have you tryed something with SharedPreferences?

  • @hollaraywaju1
    @hollaraywaju1 4 ปีที่แล้ว

    I really love this. Thanks so much

  • @alexandervasilenko7773
    @alexandervasilenko7773 4 ปีที่แล้ว

    Awesome video! Waiting for the next ones... Thanx a lot for your effort!

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว +1

      Thank you!

  • @marialijideveloper2006
    @marialijideveloper2006 4 ปีที่แล้ว +1

    Hi, 'Sensei' Reso Coder, thank you for wonderful job!!, I have this issue : [ICounterRepository] is abstract and can not be registered directly! cause this at the moment to run appears this error : 'Receiver was call on null'

  • @SEOTADEO
    @SEOTADEO 2 ปีที่แล้ว

    Very nice video, thanks a lot!

  • @nicholasmiller5731
    @nicholasmiller5731 3 ปีที่แล้ว

    Do you know if Injectable offers dependency inversion also? I was took aback when I saw you add the @bind annotation on ICounterRepository, rather than on the Dev/Prod implementations.

  • @Abion47
    @Abion47 4 ปีที่แล้ว +4

    The link for the written tutorial seems to be broken.

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว +1

      Thanks!!! Damned Wordpress 😒

  • @stevenstone307
    @stevenstone307 3 ปีที่แล้ว

    It seems to me that you should be passing ICounterRespository into the ChangeNotificationProvider. If you're explicitly passing the service class, doesn't that defeat the purpose of dependency injection?

  • @programan6391
    @programan6391 4 ปีที่แล้ว +1

    Best Flutter content

  • @rarescruceat
    @rarescruceat 4 ปีที่แล้ว

    Great tutorial! Good job!

  • @tintin537
    @tintin537 4 ปีที่แล้ว

    Thank you 🙏 keep up the good work and best wishes for you

    • @tintin537
      @tintin537 4 ปีที่แล้ว

      I just came by to tell you that I am working on a project. which this helped me a lot and saved me a ton of time.

  • @codersplayground4391
    @codersplayground4391 2 ปีที่แล้ว

    What’s that shortcut you used to correct dev to prod on both the variable and value ?

  • @afifnadaf9321
    @afifnadaf9321 4 ปีที่แล้ว

    Amazing.. very informative.

  • @scottatkinson6339
    @scottatkinson6339 4 ปีที่แล้ว

    Great video, how do you handle multiple providers though whilst using injectable? as you only use one in this video. Can anyone help?

  • @BonBaisers
    @BonBaisers 4 ปีที่แล้ว +2

    You should use @RegisterAs on implementation class instead of Bind.toType on the contract class as it introduces an "ugly" cycling dependency. Your domain must stay out from implementations.

  • @verryondrums
    @verryondrums 4 ปีที่แล้ว

    You are using an "I" in front of the abstract classes/interfaces. So it's "CounterRepository" for the actual implementation and "ICounterRepository" for the abstract class. Is this a convention? Couldnt find something on the "dart convention guide". Before you used this kind of naming you used "CounterRepository" for the abstract class and "CounterRepositoryImpl" for the implementation.

    • @scottatkinson6339
      @scottatkinson6339 4 ปีที่แล้ว +1

      Coming from a .Net background it's widely used by many developers to utilize the "I" when implementing an interface then dropping the "I" when implementing the class that will implement the interface.
      IUserServce

  • @PayamA
    @PayamA 4 ปีที่แล้ว

    Amazing. If you make a video about using injection and bloc that would be awesome

    • @khanaa13
      @khanaa13 4 ปีที่แล้ว

      What is special for the case you have Bloc? The process should be the exact same as in the video

    • @PayamA
      @PayamA 4 ปีที่แล้ว

      @@khanaa13 I'm using BlocProvider in a stateless widget and then a statefull widget as its child. this is where i get confused.

  • @vaibhavdangayachvd
    @vaibhavdangayachvd 4 ปีที่แล้ว

    How can we seperately test our development and production environment?

  • @bogdanb904
    @bogdanb904 4 ปีที่แล้ว +1

    Which would you advice to use? Provider or this? I'd like to start my first project but I can't make my mind. I'm coming from an Angular / .NET background so Dependency Injection looks appealing to me but I don't know how well it would scale in flutter.

    • @777phoenix2
      @777phoenix2 4 ปีที่แล้ว

      Provider and get_it is easy

    • @bogdanb904
      @bogdanb904 4 ปีที่แล้ว

      @@777phoenix2 What would the advantages be? Besides the boilerplate code needed for Dependency Injection.

    • @777phoenix2
      @777phoenix2 4 ปีที่แล้ว

      @@bogdanb904 I think this injectable is ugly I saw this video in the half and closed the browser because do not like it. Provider and locator pattern is easy and I think that is no boilerplate. But this is uglier than that...

    • @bogdanb904
      @bogdanb904 4 ปีที่แล้ว

      @@777phoenix2 It's not about easy / boilerplate. It's about scalability of the app. I' m talking about huge apps, not some weather app or TO-DOs app etc.

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว

      I have found that this injectable package has some unfinished parts, which is kind of expected from such a new package. As of now, you cannot register 3rd party classes easily. I wouldn't use it in big projects RIGHT NOW, but in the future? Yes!

  • @BrysonThill
    @BrysonThill 4 ปีที่แล้ว +1

    All your dev and test implementations will get bundled into your prod builds when using this strategy, right?

    • @ObiWanKenobi_IceNation
      @ObiWanKenobi_IceNation 3 ปีที่แล้ว

      Watching this a year later, and was thinking about the very same thing. The answer is yes, and I don't like it at all..

  • @karlon908
    @karlon908 4 ปีที่แล้ว +1

    Would like to see if we can connect the environment configuration to CI/CD configuration like in codemagic that would be nice, automated build and can change environment automatically.

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว +3

      You can and I will create a tutorial on that soon.

    • @karlon908
      @karlon908 4 ปีที่แล้ว

      Looking forward to it! Thanks!

  • @IngPedroAraujo
    @IngPedroAraujo 2 ปีที่แล้ว

    Great tutoril, thanks for it.
    Is it possible to implement this using Riverpod?

  • @francescofreddi4374
    @francescofreddi4374 4 ปีที่แล้ว

    i dont know why injection.dart product this: void $initGetIt(GetIt g, {String environment}) {} have GetIt g more and injection.dart go in error!

    • @marialijideveloper2006
      @marialijideveloper2006 4 ปีที่แล้ว +2

      I had the same error than you, so I did this little change :
      final getIt = GetIt.instance;
      @injectableInit
      void configureInjection(String enviroment) => $initGetIt(getIt); and now it works !!

  • @programan6391
    @programan6391 4 ปีที่แล้ว

    What's your strategy to move code between dev and prod?

  • @harshjoshi1067
    @harshjoshi1067 4 ปีที่แล้ว

    Nice one sir

  • @easazade
    @easazade 4 ปีที่แล้ว

    how do we pass parameters to factories?

  • @joeng7424
    @joeng7424 4 ปีที่แล้ว

    I don't know why we have to complicate things with these DI packages when we already have Provider & ProxyProvider in case of using Provider. And I never like code generation cause it makes me feel like I'm not in full control of my code in which I'm writing.

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว

      ProxyProvider is a complication from my point of view.

    • @bogdanb904
      @bogdanb904 4 ปีที่แล้ว

      The Inversion of Control and Dependency Injection patterns are widely used in many frameworks and programming languages. E.g. Angular, .NET (C#)

    • @777phoenix2
      @777phoenix2 4 ปีที่แล้ว

      @@bogdanb904 but you can create apps without them. It is not too hard..
      I think this injectable is too ugly, I prefer only get_it and provider...

  • @faisalmushtaq2287
    @faisalmushtaq2287 4 ปีที่แล้ว

    Can you make an App series like you made Weather Forecast app with Android but this time with Flutter.

  • @thomasmabika7291
    @thomasmabika7291 4 ปีที่แล้ว

    Map, how can I use the build in 'convert' package to turn that to json?

    • @Abion47
      @Abion47 4 ปีที่แล้ว

      Is there a particular reason you have for using a `Map` as a key for another `Map`? That seems like a recipe for a bad time.

    • @thomasmabika7291
      @thomasmabika7291 4 ปีที่แล้ว

      @@Abion47 yeah, I kind of figured, ended up using an int instead.

  • @_dinesh
    @_dinesh 4 ปีที่แล้ว +1

    Is this out an dated tutorial? @Bind is longer exist? 🙄🙄🙄

  • @arifikhsanudin9724
    @arifikhsanudin9724 4 ปีที่แล้ว

    How about end to end testing, sir?

  • @g-tensolution8527
    @g-tensolution8527 4 ปีที่แล้ว

    What about ready Signal ?

  • @kh_ysf
    @kh_ysf 4 ปีที่แล้ว

    please What's the deference be between factory and singleton and lazy Singleton!

    • @ResoCoder
      @ResoCoder  4 ปีที่แล้ว +2

      Factory creates new objects every time it's called. Singleton reuses the same object.
      Lazy singleton's instance is created only upon first request, whereas regular non-lazy singleton instance is created as soon as the app is launched in the main() method.

    • @kh_ysf
      @kh_ysf 4 ปีที่แล้ว

      @@ResoCoder many thanks 🤗🤗🤗😘 but can u make video to explain it in example? when we need to use singleton not lazy singleton for example and thanks u again 😘

  • @anaselmansory6192
    @anaselmansory6192 4 ปีที่แล้ว

    Color and icon extensions?😁

  • @peetcoetzee
    @peetcoetzee 4 ปีที่แล้ว

    Congrats. Welcome to Bitcoin SV !

  • @PH923
    @PH923 3 ปีที่แล้ว

    Thx for the video. Too much configuration imo. I love the idea of Flutter as a technology but It is still immature. This needs a CLI to automate all the config staff. We will see if Flutter gets there.

  •  4 ปีที่แล้ว

    Record a video about flutter_modular.

  • @manishgautam2424
    @manishgautam2424 ปีที่แล้ว

    Please code According to new Packages

    • @manishgautam2424
      @manishgautam2424 ปีที่แล้ว

      @module
      abstract class DiModule {
      @dev
      @injectable
      ICounterRepository devCounterRepository() => DevCounterRepository();
      @prod
      @injectable
      ICounterRepository prodCounterRepository() => CounterRepository();
      @test
      @injectable
      ICounterRepository testCounterRepository() => MockCounterRepository();
      }

  • @RIAJULISLAMI
    @RIAJULISLAMI 4 ปีที่แล้ว

    What do you think about Koin: pub.dev/packages/koin

  • @kretynek1
    @kretynek1 2 ปีที่แล้ว

    What is the point in declaring implementation upon abstraction...? You know that in most languages you would receive cycle, and even would not compile? Man, you are showing people how to code and make such things.... :|