scoped_get_it 0.0.1+1 scoped_get_it: ^0.0.1+1 copied to clipboard
get_it with scopes.
scoped_get_it #
GetIt with scopes :).
⚠️ Read First #
This package is new and API maybe unstable, you are welcome to reach the source code,it is very simple, and decide if want to use it in your project. Also check out the example
⭐ PRs are always welcome.
Installation #
dependencies:
get_It:
scoped_get_it:
How does this package works? #
It proxies calls to GetIt
and caches them as singleton in an internal GetIt
instance for each scope defined.
Injector
Widget #
This widget stores your global GetIt
instance to later be used in ScopedInjector
widget, also you simply provide your global GetIt
instance to ScopedInjector
each time you construct one through base
field.
Injector(
sl: sl,
child: MyApp(),
);
ScopedInjector
Widget #
This widget proxies calls to the global GetIt instance and stores them as singletons in a local GetIt instance.
ScopedInjector(
base: sl, /*use if you don't have an Injector parent*/
child: ...
);
How to use this package? #
- Initialize your global GetIt instance and populate it. (check out injectable).
- Wrap your app with
Injector
widget and pass it your global GetIt instance.- You can skip this step and pass the global GetIt instance to each scope instead.
- Wrap the part of tree you want a singleton scope to be defined at with
ScopedInjector
widget. - Use
ScopedInjector.get<D>(BuildContext,...)
to get your scoped dependencies.- You can also use
context.injectScoped<D>()
- You can also use