Dependency Injector Package

A package created to manage instances for your application.

Features

  • ⭐ Register an instance passing the Type, a typedef InstanceCreator<T> = T Function(), and true or false for isSingleton property. By default isSingleton 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>();

Getting started

Import the package on the pubspec.yaml.

dependencies:
  dependency_injector:
    git: https://github.com/Luanftg/dependency_injector

Usage

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>();
}

Additional information

Author: Luan Fonseca Torralbo Gimenez

Foto do Luan Fonseca Torralbo Gimenez
Luan F. T. Gimenez