injectable_generator 0.4.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 94

injectable_generator #

A generator for injectable library.

ChangeLog #

[0.4.1] #

  • Fix stack overflow issue #78

[0.4.0] Breaking Changes! #

  • Change Methods inside of register modules are treated as factory methods now, so all params are considered injected params unless annotated with @factoryParam.
  • Change registerModule is now replaced with @module
  • Change RegisterAs(Type) Annotation is now replaced with @Injectable(as:Type)
  • Change Singleton.Lazy() is replaced with @LazySingleton()
  • Add generateForDir property to @InjectableInt to specify what directories to generate for.
  • Fix imports issue when working with bin directory

[0.3.5] #

  • Fix non-primitive factory params aren't imported

[0.3.4] #

  • fix parameterized dependencies aren't resolved properly
  • minor fixes

[0.3.3] #

  • fix duplicate var names issue when pre-resolving multiple instances of the same type

[0.3.2] #

  • fix registered abstract dependencies are reported missing.
  • fix registering third party types as singleton throws an error.

[0.3.1] #

  • fix resolve by instanceName is using positional var instead of named
  • fix part files are imported as stand alone
  • minor fixes

[0.3.0] Breaking Changes! #

  • add support for GetIt 4.0.0
  • fix generic types are registered as dynamic
  • fix unresolved future when registering asynchronous dependencies
  • change asynchronous dependencies will be registered using async factory unless annotated with @preResolve

[0.2.4] #

  • fix type arguments are not imported.
  • fix get with instanceName missing type.

[0.2.3] #

  • improve support for custom initializers
  • fix src import issue

[0.2.2] #

  • remove flutter dependency
  • add support for custom initializers in register Modules
  • minor fixes

[0.2.1] #

  • fix typo in @Environment annotation
  • ignore abstract classes in auto mode.

[0.2.0] Breaking Changes! #

  • You now need to pass in your getIt instance to @initGetIt() func
  • Rename @Bind to @RegisterAs to avoid confusion because, now we're annotating the implementation not the abstract.
  • Add @factoryMethod annotation to mark named factories and static create methods.
  • Add @registerModule annotation to support registering third party types.
  • Fix eager singletons are registered before their dependencies.

[0.1.0] #

  • initial release

example/README.md

Example #


import 'package:injectable/injectable_annotations.dart';

abstract class Service {}

@RegisterAs(Service, env: 'dev')
@injectable
class ServiceImpl1 extends Service {}

@RegisterAs(Service, env: 'prod')
@injectable
class ServiceImpl2 implements Service {

}

@injectable
class MyRepository {
  MyRepository(@Named.from(ServiceImpl1) Service service);
}

Use this package as a library

1. Depend on it

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


dependencies:
  injectable_generator: ^0.4.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:injectable_generator/injectable_generator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
89
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because:

  • package:injectable_generator/injectable_generator.dart that imports:
  • package:injectable_generator/dependency_resolver.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on ios

Because:

  • package:injectable_generator/injectable_generator.dart that imports:
  • package:injectable_generator/dependency_resolver.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on linux

Because:

  • package:injectable_generator/injectable_generator.dart that imports:
  • package:injectable_generator/dependency_resolver.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on macos

Because:

  • package:injectable_generator/injectable_generator.dart that imports:
  • package:injectable_generator/dependency_resolver.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-native on windows

Because:

  • package:injectable_generator/injectable_generator.dart that imports:
  • package:injectable_generator/dependency_resolver.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Package not compatible with runtime flutter-web on web

Because:

  • package:injectable_generator/injectable_generator.dart that imports:
  • package:injectable_generator/dependency_resolver.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/utils.dart that imports:
  • package:build/build.dart that imports:
  • package:build/src/generate/run_post_process_builder.dart that imports:
  • package:build/src/builder/post_process_builder.dart that imports:
  • package:build/src/builder/builder.dart that imports:
  • package:build/src/builder/build_step.dart that imports:
  • package:build/src/asset/reader.dart that imports:
  • package:glob/glob.dart that imports:
  • package:glob/src/list_tree.dart that imports:
  • package:glob/src/io.dart that imports:
  • package:glob/src/io_export.dart that imports:
  • dart:io

Package not compatible with runtime js

Because:

  • package:injectable_generator/injectable_generator.dart that imports:
  • package:injectable_generator/dependency_resolver.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/utils.dart that imports:
  • package:build/build.dart that imports:
  • package:build/src/generate/run_post_process_builder.dart that imports:
  • package:build/src/builder/post_process_builder.dart that imports:
  • package:build/src/builder/builder.dart that imports:
  • package:build/src/builder/build_step.dart that imports:
  • package:build/src/asset/reader.dart that imports:
  • package:glob/glob.dart that imports:
  • package:glob/src/list_tree.dart that imports:
  • package:glob/src/io.dart that imports:
  • package:glob/src/io_export.dart that imports:
  • dart:io

Package not compatible with runtime native-aot

Because:

  • package:injectable_generator/injectable_generator.dart that imports:
  • package:injectable_generator/dependency_resolver.dart that imports:
  • package:source_gen/source_gen.dart that imports:
  • package:source_gen/src/type_checker.dart that imports:
  • dart:mirrors

Health issues and suggestions

Document public APIs. (-0.57 points)

134 out of 136 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/dependency_resolver.dart. (-0.50 points)

Analysis of lib/dependency_resolver.dart reported 1 hint:

line 16 col 63: 'RegisterAs' is deprecated and shouldn't be used. Use @Injectable(as:...) or it's subs instead.

Fix lib/generator/register_func_generator.dart. (-0.50 points)

Analysis of lib/generator/register_func_generator.dart reported 1 hint:

line 1 col 8: Unused import: 'package:injectable/injectable.dart'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
analyzer >=0.39.2 <0.40.0 0.39.12
build ^1.0.0 1.3.0
glob ^1.1.7 1.2.0
injectable ^0.4.0 0.4.0+1
source_gen ^0.9.0 0.9.6
Transitive dependencies
_fe_analyzer_shared 5.0.0
args 1.6.0
async 2.4.2
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
html 0.14.0+3
js 0.6.2
logging 0.11.4
meta 1.2.2 1.3.0-nullsafety
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
pedantic 1.9.2
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
build_runner ^1.0.0
build_test any
mockito any
path any 1.7.0
test any