organic_injector 0.0.4

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 79

organic_injection

dependency injector for flutter that works out of the box without mirrors. Used https://github.com/dotdotcommadot/dart_robotlegs_di as a base to do this simple no mirrors implementation.

Getting Started

Use Injector.instance singleton to access the injector, or wrap it inside your own singleton.

map type to a already instantiated value.

  injector.mapToValue(CounterModel, new CounterModel());

Optionally add name.

  injector.mapToValue(ChangeNotifier,new ChangeNotifier(), name: 'counter_changed');

One advice can be to wrap basic types to distinct classes to avoid confusion.

Injector will return instance that was previously mapped

CounterModel counterModel = injector.getInstance(CounterModel) as Counter;

ChangeNotifier changeNotifier = injector.getInstance(ChangeNotifier,'counter_changed') as ChangeNotifier;

map to a provider

class SecureRandomProvider implements IProvider{

  final Random secure = Random.secure();
  
  @override
  void destroy() {
  }

  @override
  apply({Type type}) => SecureRandom(secure.nextDouble());
}

class SecureRandom {
  final double random;
  const SecureRandom(this.random);
}  

injector.mapToProvider(SecureRandom,new SecureRandomProvider());

later when you inject into SecureRandom, you will always get unique crypto secure double.

double SecureRandom secureRandom = injector.getInstance(SecureRandom) as SecureRandom;
  

If you want to provide dependecies of previously mapped values to your mapping, implement IInjectable into the class. Injector will then auto populate mappings

Implement IInjectable to provide chain injection.

class CounterModel implements IInjectable {
 
@override
void inject(IInjector injector){
    //get your mappings here
  }
}

get it on pub pub.

and check example project github.

great thanks to robotlegs 2 team for actionscript and https://github.com/dotdotcommadot/dart_robotlegs_di for starting this implementation in dart.

Changelog

0.0.1

  • Initial version, created by Stagehand

0.0.3

  • Updated Readme with links

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  organic_injector: "^0.0.4"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


      import 'package:organic_injector/organic_injector.dart';
  
Version Uploaded Documentation Archive
0.0.4 Mar 28, 2018 Go to the documentation of organic_injector 0.0.4 Download organic_injector 0.0.4 archive
0.0.3 Mar 17, 2018 Go to the documentation of organic_injector 0.0.3 Download organic_injector 0.0.3 archive
0.0.2 Mar 17, 2018 Go to the documentation of organic_injector 0.0.2 Download organic_injector 0.0.2 archive
0.0.1 Mar 17, 2018 Go to the documentation of organic_injector 0.0.1 Download organic_injector 0.0.1 archive

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
65 / 100
Health:
Code health derived from static analysis. [more]
95 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90 / 100
Overall score:
Weighted score of the above. [more]
79
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:organic_injector/organic_injector.dart.

Suggestions

  • Homepage does not exists.

    We were unable to access https://github.com/matejthetree/organic_injector at the time of the analysis.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 13 hints.

    Run dartfmt to format lib/organic_injector.dart.

    Run dartfmt to format lib/src/errors/injector_error.dart.

    Similar analysis of the following files failed:

    • lib/src/errors/injector_missing_mapping_error.dart (hint)
    • lib/src/i_injector.dart (hint)
    • lib/src/injectables/injectable.dart (hint)
    • lib/src/injector.dart (hint)
    • lib/src/mapping/injection_mapping.dart (hint)
    • lib/src/providers/i_provider.dart (hint)
    • lib/src/providers/value_provider.dart (hint)
  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use organic_injector.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
Dev dependencies
test ^0.12.0