Get_It package - Dependency Injection with Service Locator Pattern in Flutter & Dart

Поділитися
Вставка
  • Опубліковано 4 лис 2020
  • You want to glue together your different layers in your application, then this package is for you. The Get_It package brings an easy to use Service Locator directly into your application. The Service Locator will make it super easy to connect your app and your different layers together.
    If you want to see Max when he is Live Streaming, checkout kick.com/devcafe
    #GetIt #Flutter #Dart
    You like our work and would like to support us, feel free to join us on Patreon.
    / flutterexp
    Get_it on pub.dev
    pub.dev/packages/get_it
    State Management with Get_it?
    pub.dev/packages/get_it_mixin
    ** Social Medias **
    Website: flutter-explained.dev
    Say hi to Max
    Twitter: / flutter_exp
    GitHub Max: github.com/md-weber
    LinkedIn: / max-weber-9889a3ba
    Say hi to Mahtab
    Twitter Mahtab: / mahtab_dev
    GitHub Mahtab: github.com/mt-tadayon

КОМЕНТАРІ • 77

  • @emmanuelolajubu4144
    @emmanuelolajubu4144 3 місяці тому +2

    Even after 3years, i still find this video helpful

  • @michaelokhaimoh6809
    @michaelokhaimoh6809 2 роки тому +11

    After searching the internet and reading medium articles to little satisfaction, this did justice to everything. Thank you very much. Subscribed!!

  • @makemypetgamedevprocess6475
    @makemypetgamedevprocess6475 3 роки тому +1

    Finally!!! I was now able to understand how to use it and what is it, thanks :)

  • @ManontheOutside
    @ManontheOutside Рік тому +1

    Thanks, this is a great explanation. I struggled to understand this until I found your video. Thanks so much!

  • @juliusherbert709
    @juliusherbert709 Рік тому +1

    I have commented probably 4 to 5 times on UA-cam. And this is the 6 times. I just wanted to say thanks for the well-structured teaching approach! Awesome teacher. I'd like the to-do style used to walk me through the video and the justification of each step. Amazing flow!

  • @nbits7433
    @nbits7433 2 роки тому +1

    Quality content. Thank you.

  • @ionolaru4086
    @ionolaru4086 3 роки тому +7

    Dependency Injection Pattern left the chat

  • @Vlad100333
    @Vlad100333 2 роки тому +1

    Really cool, thanks my dear friend

  • @googleuser2355
    @googleuser2355 3 роки тому +1

    I was too lazy to read the documentation 😂.. thanks you were there🥰

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

    very brief and helpful.

  • @winniecole7276
    @winniecole7276 5 місяців тому

    Very informative 👏

  • @saliouseck4263
    @saliouseck4263 3 роки тому +1

    thank's very much very clear

  • @anasalbattiri003
    @anasalbattiri003 Рік тому +1

    Thank you very much!

  • @ahmedamineguerraiche5672
    @ahmedamineguerraiche5672 10 місяців тому

    thank you very much

  • @yonathanhailemelekot5238
    @yonathanhailemelekot5238 Рік тому

    you make it super easy. and that is not fair🤣

  • @keyonlewis7574
    @keyonlewis7574 3 місяці тому

    Thanks a lot

  • @ahmedadnan5875
    @ahmedadnan5875 3 роки тому +3

    good example for how to use get_it in real project, thanks

    • @FlutterExplained
      @FlutterExplained  3 роки тому +1

      You are most welcome :) I hope it helps you along the way!

  • @EnriqueLeyvaJose
    @EnriqueLeyvaJose 2 місяці тому

    Thanks for the video Max, Could you do one please using GetIt in tests? Cheers from Sauerland

  • @christianmarpert3844
    @christianmarpert3844 2 роки тому +3

    I really like the idea of a service locator, especially that it is flutter independent as I understand. In other words, I don't need to pass something around the widgets like with provider. I would be interested, if this works well with the bloc pattern. instead of flutter_bloc, which uses provider under the hood for DI, couldn't I use get_it? Would be great if you could share your thoughts on that. Thks for the great video!

  • @moazelsawaf2000
    @moazelsawaf2000 Рік тому

    Thanks a lot ❤

  • @hasankemalturk4416
    @hasankemalturk4416 2 роки тому +1

    Thanks to you :)

  • @user-kw9cu
    @user-kw9cu 2 роки тому +1

    thank you i get it

  • @thomasmoore2870
    @thomasmoore2870 2 роки тому

    Thanks!!

  • @Flutterdev6391
    @Flutterdev6391 3 роки тому +1

    Thanks

  • @kopianan
    @kopianan 3 роки тому

    hi there, how to unregister singleton using injectable ?

  • @isurujn
    @isurujn 2 роки тому +2

    Thanks for the tutorial. I do have a question. This approach kind of goes against dependancy injection pattern, doesn't it? Having a global object that exposes all its members to anything is the opposite of DI, right? Isn't it bad?

  • @jai6133
    @jai6133 3 роки тому

    Can you make an video for getit with provider ?

  • @tawandagutsa5993
    @tawandagutsa5993 3 роки тому +2

    Excellent video! I do have a question though, if you can help. I was hoping get_It would be a state management solution that automatically updates the UI when changes are made like provider with notifylisteners, without the context from a widget being required. You've made it clear it's not. Are there any state management packages that can do the same thing provider can do, but without the context? Thanks in advance

    • @FlutterExplained
      @FlutterExplained  3 роки тому +1

      You can actually use GetIT also as a state management solution nowadays you will need to use the package: get_it_mixing
      pub.dev/packages/get_it_mixin

  • @caballero75RS
    @caballero75RS 3 роки тому +2

    Great class. I would like to see now an integration with provider for state management. Could i use 'with changeNotifier' in MemeRepo class? Thanks

    • @burakbirer
      @burakbirer 3 роки тому +3

      That would be get_it_mixin i guess?

    • @FlutterExplained
      @FlutterExplained  3 роки тому +3

      ​@@burakbirer Yes get_it_mixin will do the job!

    • @escamoteur
      @escamoteur 3 роки тому +2

      Directly combining with provider doesn't make much sense. But state_notifier would be an option. But I highly recommend to check out the get_it_mixin which makes get_it to a full state management solution.

    • @burakbirer
      @burakbirer 3 роки тому +1

      @@escamoteur then we absolutely need a detailed video about best practices with get_it_mixin 💙

    • @burakbirer
      @burakbirer 3 роки тому +2

      @@FlutterExplained May we take your answer as an upcoming tutorial on get_it_mixin ? That would be great!

  • @ziyadmansy6016
    @ziyadmansy6016 2 роки тому +1

    What are the use cases of this when i can normally use the normal dependency injection in Provider for example? any singleton class would do that then where is the advantage?

    • @FlutterExplained
      @FlutterExplained  2 роки тому +1

      Very good question, of course you are able to use provider for that. It is even nearly the same idea. It is more about what tool to use for which problem. Get_it is specifically for DI while Provider should be a state management solution.

  • @user-su4yk5ph6v
    @user-su4yk5ph6v 3 роки тому +2

    👍🏻

  • @ben6
    @ben6 3 роки тому +2

    ServiceLocator seems to be "god-singleton" class. Never did i think of using 2 really bad words in programming at the same time.

    • @FlutterExplained
      @FlutterExplained  3 роки тому

      Hi Ben, thanks for your feedback and your concern, maybe I did not explain it correctly but ServiceLocator is not a God Singleton, it is a registration library for singletons. Maybe I did not use it perfectly here in the video but this is a general idea. The pattern exists already quite some time but it is pretty much debated. In my research, I talked with a lot of people and figured out that there are a lot of people who love it and a lot who hate it. In my opinion, it heavily depends on your use case and how you and your team want to work.
      I hope that clarifies things :) en.wikipedia.org/wiki/Singleton_pattern

  • @hamourabimr3826
    @hamourabimr3826 Рік тому +1

    Hi.. Would like to know the config you used with your vscode? Theme, font.. thanks

    • @FlutterExplained
      @FlutterExplained  Рік тому

      I use in general Fire font with nerd icons and as a Theme I am using usually the One Dark Theme.

  • @rudranshawasthi7291
    @rudranshawasthi7291 3 роки тому

    I have a quesion why did we not use a memeDomainCOntroler when we could directly call the meme repo as thats what is happening.

  • @syahrul7493
    @syahrul7493 3 роки тому +1

    Please subtitle on you video. Im from indonesia

  • @jutt342
    @jutt342 2 роки тому

    I have a question pls guide, how GetIt handles garbage collector as it registeres so many object before hand does it mean all those objects will remain in memory till app lifecycle ? or Objects will be wiped off by garbage collector if yes then when pls guide

    • @FlutterExplained
      @FlutterExplained  2 роки тому +1

      Very good question, AFAIK if you will not clean them up they will stay in Memory you will need to create some kind of mechanism to clean them up. Lazy loading Singeltons will be created when they are needed but will also leave a footprint afterwards.

  • @numberone6660
    @numberone6660 3 роки тому +2

    Why we not just create a meme object and to use getMeme?

    • @FlutterExplained
      @FlutterExplained  3 роки тому +1

      Great question, the problem is if you directly create the MemeRepo or MemeDomainController object and get the meme you have a strong dependency between both, this means if you want to for example create a Test you will have no chance to replace the Services with something you like. Therefore you will have to test the whole application rather then only the function.
      You can find more to this topic if you search for Dependency Injection:
      martinfowler.com/articles/injection.html

  • @user-kh6rp6yx1j
    @user-kh6rp6yx1j Місяць тому

    Hello man.

  • @francescofreddi4374
    @francescofreddi4374 3 роки тому

    but..... all benefit about stateManagement is broken by setState........

    • @FlutterExplained
      @FlutterExplained  3 роки тому

      Get_It is not a state management solution. Therefore it is not really broke. It is a service provider, and you have access to different layers. If you search for a state management solution, please have a look into get_it_mixins :)

    • @francescofreddi4374
      @francescofreddi4374 3 роки тому

      @@FlutterExplained you have reason!!
      mmmm more of less is like Provider... right?

    • @escamoteur
      @escamoteur 3 роки тому +1

      @@francescofreddi4374 yes, but you don't need a Buildcontext and it offers some other nice functionality. together with the get_it_mixin it gets a full state mangement solution

  • @ElVerdaderoAbejorro
    @ElVerdaderoAbejorro Рік тому +1

    Please don't mislead non-senior devs into thinking this is dependency injection. A service locator is not the same as dependency injection. SL is actually an anti pattern (the book "Dependency Injection: Principles, Practices and Patterns" explains why). For a real DI library for Dart/Flutter see Inject.

    • @FlutterExplained
      @FlutterExplained  Рік тому

      Thanks for your feedback. You are right the Service Locator Pattern (SL) can be a anti pattern because its over usage but I would not generalize it as "you should never use it because it is bad". I know also a lot of large project who overuse, and overcomplicated with a SL but there are as always some nice niche cases for it (especially in Server Dev).
      Sorry if I made that not super clear in the video, maybe I can create a follow up in the next month :).

  • @askin_bilir
    @askin_bilir 3 роки тому +1

    I think Get X could be a better alternative because many things can be done with one package

    • @FlutterExplained
      @FlutterExplained  3 роки тому +3

      AFAIK GetX would also solve this problem because it has a strong DI implementation. However I am personally not a big fan of GetX.

    • @_undecided
      @_undecided 3 роки тому +1

      GetX is most bloatware state management for me and people are deceived because not need use context and very short lines. Remember what I say. Using GetX without context is dangerous with Responsive Layouts and what is short and simple is not mean best it will eat your errors in the background or can be hard to test and.... Even Bloc is better choose. But of course it's you choose.

    • @askin_bilir
      @askin_bilir 3 роки тому

      @@_undecided For state management I prefer flutter block or provider. I have never used GetX in a real project. I just saw its popularity, usability and features. These options was catchy for me. If you are saying these, probably you had tested it.

    • @leoingson
      @leoingson 3 роки тому +2

      ​@@FlutterExplained Hey, care to elaborate why you're not the biggest fan? I've seen some reservations, but GetX seemed to be a state management candidate.. Paar kurze Worte reichen :)

    • @FlutterExplained
      @FlutterExplained  3 роки тому +10

      ​@@leoingson Hi there, sure. GetX is an amazing package but also a great example of a so-called golden hammer pattern. It promises everything out of the box and a lot of people will tend to use it. The problem is that you create another strong dependency between your project and GetX. So let's say I managed my State with GetX now something goes wrong in GetX and I strongly depend on the library, what happens if the main maintainer of the package is gone? Can I replace GetX easily? Do I understand the core of GetX. What happens if the GetX team drives a decision I am not willing to take in my application. Suddenly I have to remove the whole package and because it is everywhere, basically I will throw away my application.
      If I would take a package that has only one single responsibility, that does not violate the Single Responsibility Principle. It is way easier to substitute it with something else. You could argue that you only want to use GetX for a single purpose, but even there if you have a team you can maybe speak for yourself, but you cannot make sure that nobody will use the offered power.
      GetX remembers me a lot to jQuery, it also offered a lot and made it possible to wrap most of your JavaScript code, but boy it was horrible when we needed to get rid of it. This is just my opinion, and I will also create sooner or later a video where I talk a bit more in deep about it.