simple_injector 0.1.2 simple_injector: ^0.1.2 copied to clipboard
Inject your dependencies simply and quickly. The dependency is created in the measure that it is injected.
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();