Provider vs. Get_it

前端 未结 3 1128
醉酒成梦
醉酒成梦 2021-02-07 01:56

Searching for Dependency Injection solutions for Flutter, I found two awesome libraries: provider and get_it.

As far as I can see, provid

3条回答
  •  情话喂你
    2021-02-07 02:54

    Get It is not a dependency injection solution but a service locator.

    It's useful if you want to rapidly switch between two or more implementations of a class. For example to mockup a service, and change between the "real" service or the fake one (for debugging purpose).

    Indeed it can't retrieve/supply reference to an existing object (exception is for singleton, but you can do the same by yourself without much more effort) and can supply only new objects.

提交回复
热议问题