simple_injector 0.1.0 copy "simple_injector: ^0.1.0" to clipboard
simple_injector: ^0.1.0 copied to clipboard

discontinued
outdated

Simple Injector DI

pub package

SimpleInjector #

Simple Injector DI

Usage #

To use this plugin, add simple_injector as a dependency in your pubspec.yaml file.

Example #

Before configure is necessary create module of the inject. Example:


import 'package:simple_injector/module_injector.dart';
import 'package:simple_injector/simple_injector.dart';

class RepositoryModulo extends ModuleInjector{

  ///in the constructor we add what should be injected by passing: type and the method that creates it (optional isSingleton if desired)
  RepositoryModulo(){
    add(RepositoryTest, repositoryTest, isSingleton: true);
    add(RepositoryTest2, repositoryTest2);
  }

  RepositoryTest repositoryTest(){
      return RepositoryTestImpl();
  }

  RepositoryTest2 repositoryTest2(){
    return RepositoryTest2Impl(
      SimpleInjector().inject()
    );
  }

}

After the module created we configured our SimpleInjector in the constructor app

import 'package:simple_injector/simple_injector.dart';

MyApp(){
    SimpleInjector.configure(Flavor.PROD);
    SimpleInjector().registerModule(RepositoryModulo());
  }

All ready! you can register as many modules as you want. to inject air into a configured dependency, just add this:


RepositoryTest repository = SimpleInjector().inject();

or

final repository = SimpleInjector().<RepositoryTest>inject();

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Simple Injector DI

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on simple_injector