A package created to manage instances for your application.
- ⭐ Register an instance passing the
Type
, atypedef InstanceCreator<T> = T Function()
, andtrue
orfalse
forisSingleton
property. By defaultisSingleton
property is set to true.
void register<T extends Object>(
InstanceCreator<T> instance, {
bool isSingleton = true,
})
- ⭐ Get an instance of a register Type.
T get<T extends Object>()
- ⭐ Callable Interface for the get method.
call<T extends Object>() => get<T>();
Import the package on the pubspec.yaml
.
dependencies:
dependency_injector:
git: https://github.com/Luanftg/dependency_injector
This is a simple example for the entire usage of this package.
import 'package:dependency_injector/dependency_injector_base.dart';
Future<void> main() async{
final di = DependencyInjector();
//register a Type
di.register<DBConfiguration>(() => MySqlDBConfiguration());
//get an instance
final userAPi = di.get<UserApi>();
//get from callable interface
final userAPi = di<UserApi>();
}
Luan F. T. Gimenez |