get_it_di_global_variable 0.0.5
get_it_di_global_variable: ^0.0.5 copied to clipboard
A tiny Dart package that exposes a global instance of GetIt (sl) for easy and consistent dependency injection across your Flutter or Dart project.
get_it_di_global_variable #
A simple Dart package that provides a globally accessible instance of GetIt
, a popular service locator for dependency injection in Flutter and Dart apps.
🔧 Installation #
Add this package to your pubspec.yaml
:
dependencies:
get_it_di_global_variable: ^0.0.5
Then run:
flutter pub get
🚀 Usage #
This package exposes a globally accessible instance of GetIt
named sl
, which is short for "service locator".
Import the package: #
import 'package:get_it_di_global_variable/get_it_di_global_variable.dart';
Register your dependencies: #
sl.registerSingleton<ApiService>(ApiService());
Retrieve your dependencies: #
final apiService = sl<ApiService>();
📦 Provided Code #
import 'package:get_it/get_it.dart';
final GetIt sl = GetIt.I;
🎯 Why use this? #
- Avoid boilerplate in each file to define a
GetIt
instance. - Cleaner and more readable dependency registration and access.
- Common convention (
sl
) used in many Flutter projects.
📝 License #
This package is released under the MIT License.