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

discontinued
outdated

Inject your dependencies simply and quickly. The dependency is created in the measure that it is injected.

pub package

SimpleInjector #

Inject your dependencies simply and quickly. The dependency is created in the measure that it is injected, if it is configured singleton it is created only in the first one that is injected.

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(
      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
40
pub points
0%
popularity

Publisher

unverified uploader

Inject your dependencies simply and quickly. The dependency is created in the measure that it is injected.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on simple_injector