lite_ref 0.0.2
lite_ref: ^0.0.2 copied to clipboard
A lightweight dependency injection package.
Overview #
Lite Ref is a lightweight dependency injection library for Dart and Flutter.
Installation #
dart pub add lite_ref
Usage #
LifeRefs are lazy. They are only instantiated when you call instance
or ()
.
import 'package:lite_ref/lite_ref.dart';
// create a singleton
var dbRef = LiteRef(() => Database());
// use it
// refs are also callable so you can replace dbRef.instace with dbRef()
var db = await dbRef.instance;
// override for testing
dbRef.overrideWith(() => MockDatabase());
// create a transient (always new instance)
var userService = LiteRef(() => UserService(database: dbRef()), cache: false);