angel_container_generator 1.0.0

  • README.md
  • Example
  • Installing
  • Versions
  • new46

container_generator

A better IoC container for Angel, ultimately allowing Angel to be used without dart:mirrors.

Codegen support for using pkg:reflectable with pkg:angel_container.

example/main.dart

import 'package:angel_container/angel_container.dart';
import 'package:angel_container_generator/angel_container_generator.dart';

@GlobalQuantifyCapability(
    r'^dart\.core\.(Iterable|List|String|int|Object)', contained)
import 'package:reflectable/reflectable.dart';

import 'package:test/test.dart';

// ignore: uri_does_not_exist
import 'reflector_test.reflectable.dart';

void main() {
  // ignore: undefined_function
  initializeReflectable();
  var reflector = const GeneratedReflector();
  Container container;

  setUp(() {
    container = new Container(reflector);
    container.registerSingleton(new Artist(name: 'Stevie Wonder'));
  });

  group('reflectClass', () {
    var mirror = reflector.reflectClass(Artist);

    test('name', () {
      expect(mirror.name, 'Artist');
    });
  });

  test('inject constructor parameters', () {
    var album = container.make<Album>();
    print(album.title);
    expect(album.title, 'flowers by stevie wonder');
  });

  testReflector(reflector);
}

@contained
void returnVoidFromAFunction(int x) {}

void testReflector(Reflector reflector) {
  var blaziken = new Pokemon('Blaziken', PokemonType.fire);
  Container container;

  setUp(() {
    container = new Container(reflector);
    container.registerSingleton(blaziken);
  });

  test('get field', () {
    var blazikenMirror = reflector.reflectInstance(blaziken);
    expect(blazikenMirror.getField('type').reflectee, blaziken.type);
  });

  /*
  group('reflectFunction', () {
    var mirror = reflector.reflectFunction(returnVoidFromAFunction);

    test('void return type returns dynamic', () {
      expect(mirror.returnType, reflector.reflectType(dynamic));
    });

    test('counts parameters', () {
      expect(mirror.parameters, hasLength(1));
    });

    test('counts types parameters', () {
      expect(mirror.typeParameters, isEmpty);
    });

    test('correctly reflects parameter types', () {
      var p = mirror.parameters[0];
      expect(p.name, 'x');
      expect(p.isRequired, true);
      expect(p.isNamed, false);
      expect(p.annotations, isEmpty);
      expect(p.type, reflector.reflectType(int));
    });
  }, skip: 'pkg:reflectable cannot reflect on closures at all (yet)');
  */

  test('make on singleton type returns singleton', () {
    expect(container.make(Pokemon), blaziken);
  });

  test('make with generic returns same as make with explicit type', () {
    expect(container.make<Pokemon>(), blaziken);
  });

  test('make on aliased singleton returns singleton', () {
    container.registerSingleton(blaziken, as: StateError);
    expect(container.make(StateError), blaziken);
  });

  test('constructor injects singleton', () {
    var lower = container.make<LowerPokemon>();
    expect(lower.lowercaseName, blaziken.name.toLowerCase());
  });

  test('newInstance works', () {
    var type = container.reflector.reflectType(Pokemon);
    var instance =
        type.newInstance('changeName', [blaziken, 'Charizard']).reflectee
            as Pokemon;
    print(instance);
    expect(instance.name, 'Charizard');
    expect(instance.type, PokemonType.fire);
  });

  test('isAssignableTo', () {
    var pokemonType = container.reflector.reflectType(Pokemon);
    var kantoPokemonType = container.reflector.reflectType(KantoPokemon);

    expect(kantoPokemonType.isAssignableTo(pokemonType), true);
    expect(
        kantoPokemonType
            .isAssignableTo(container.reflector.reflectType(String)),
        false);
  });
}

@contained
class LowerPokemon {
  final Pokemon pokemon;

  LowerPokemon(this.pokemon);

  String get lowercaseName => pokemon.name.toLowerCase();
}

@contained
class Pokemon {
  final String name;
  final PokemonType type;

  Pokemon(this.name, this.type);

  factory Pokemon.changeName(Pokemon other, String name) {
    return new Pokemon(name, other.type);
  }

  @override
  String toString() => 'NAME: $name, TYPE: $type';
}

@contained
class KantoPokemon extends Pokemon {
  KantoPokemon(String name, PokemonType type) : super(name, type);
}

@contained
enum PokemonType { water, fire, grass, ice, poison, flying }

@contained
class Artist {
  final String name;

  Artist({this.name});

  String get lowerName {
    return name.toLowerCase();
  }
}

@contained
class Album {
  final Artist artist;

  Album(this.artist);

  String get title => 'flowers by ${artist.lowerName}';
}

@contained
class AlbumLength {
  final Artist artist;
  final Album album;

  AlbumLength(this.artist, this.album);

  int get totalLength => artist.name.length + album.title.length;
}

Use this package as a library

1. Depend on it

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


dependencies:
  angel_container_generator: ^1.0.0

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:angel_container_generator/angel_container_generator.dart';
  
Version Uploaded Documentation Archive
1.0.0 Nov 30, 2018 Go to the documentation of angel_container_generator 1.0.0 Download angel_container_generator 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

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

Maintenance issues and suggestions

Maintain CHANGELOG.md. (-20 points)

Changelog entries help clients to follow the progress in your code.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
angel_container ^1.0.0-alpha 1.0.0
reflectable ^2.0.0 2.0.8
Transitive dependencies
analyzer 0.33.6 0.34.0
args 1.5.1
async 2.0.8
build 1.0.1
build_config 0.3.1+4
build_resolvers 0.2.2+6
build_runner_core 1.1.1
built_collection 4.1.0
built_value 6.1.6
charcode 1.1.2
code_builder 3.1.3
collection 1.14.11
convert 2.0.2
crypto 2.0.6
csslib 0.14.6
dart_style 1.2.0 1.2.1
fixnum 0.10.9
front_end 0.1.6+8 0.1.7
glob 1.1.7
graphs 0.1.3+1
html 0.13.3+3
http 0.12.0
http_multi_server 2.0.5
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 2.0.0
kernel 0.3.6+8 0.3.7
logging 0.11.3+2
matcher 0.12.4
meta 1.1.6
mime 0.9.6+2
package_config 1.0.5
package_resolver 1.0.6
path 1.6.2
pedantic 1.3.0
plugin 0.2.0+3
pool 1.3.6
pub_semver 1.4.2
pubspec_parse 0.1.2+3
quiver 2.0.1
shelf 0.7.3+3
shelf_web_socket 0.2.2+4
source_span 1.4.1
stack_trace 1.9.3
stream_channel 1.6.8
stream_transform 0.0.14+1
string_scanner 1.0.4
timing 0.1.1+1
typed_data 1.1.6
utf 0.9.0+5
watcher 0.9.7+10
web_socket_channel 1.0.9
yaml 2.1.15
Dev dependencies
build_runner ^1.0.0 1.1.2
build_test any
test ^1.0.0