angel_container 1.0.0-alpha.12

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 71

container

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

1.0.0-alpha.12

  • StaticReflector now defaults to empty arguments.

1.0.0-alpha.11

  • Added StaticReflector.

1.0.0-alpha.10

  • Added Container.registerLazySingleton<T>.
  • Added named singleton support.

1.0.0-alpha.9

  • Added Container.has<T>.

1.0.0-alpha.8

  • Fixed a bug where _ReflectedTypeInstance.isAssignableTo always failed.
  • Added @GenerateReflector annotation.

1.0.0-alpha.7

  • Add EmptyReflector.
  • ReflectedType.newInstance now returns a ReflectedInstance.
  • Moved ReflectedInstance.invoke to ReflectedFunction.invoke.

1.0.0-alpha.6

  • Add getField to ReflectedInstance.

1.0.0-alpha.5

  • Remove concrete type from ReflectedTypeParameter.

1.0.0-alpha.4

  • Safely handle void return types of methods.

1.0.0-alpha.3

  • Reflecting void in MirrorsReflector now forwards to dynamic.

1.0.0-alpha.2

  • Added ReflectedInstance.reflectee.

1.0.0-alpha.1

  • Allow omission of the first argument of Container.make, to use a generic type argument instead.
  • singleton -> registerSingleton
  • Add createChild, and support hierarchical containers.

example/main.dart

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

void main() {
  // Create a container instance.
  var container = new Container(const MirrorsReflector());

  // Register a singleton.
  container.registerSingleton<Engine>(Engine(40));

  // You can also omit the type annotation, in which the object's runtime type will be used.
  // If you're injecting an abstract class, prefer the type annotation.
  //
  // container.registerSingleton(Engine(40));

  // Register a factory that creates a truck.
  container.registerFactory<Truck>((container) {
    return _TruckImpl(container.make<Engine>());
  });

  // Use `make` to create an instance.
  var truck = container.make<Truck>();

  // Register a named singleton.
  container.registerNamedSingleton('the_truck', truck);

  // Should print: 'Vroom! I have 40 horsepower in my engine.'
  truck.drive();

  // Should print the same.
  container.findByName<Truck>('the_truck').drive();

  // We can make a child container with its own factory.
  var childContainer = container.createChild();

  childContainer.registerFactory<Truck>((container) {
    return _TruckImpl(Engine(5666));
  });

  // Make a truck with 5666 HP.
  childContainer.make<Truck>().drive();

  // However, calling `make<Engine>` will return the Engine singleton we created above.
  print(childContainer.make<Engine>().horsePower);
}

abstract class Truck {
  void drive();
}

class Engine {
  final int horsePower;

  Engine(this.horsePower);
}

class _TruckImpl implements Truck {
  final Engine engine;

  _TruckImpl(this.engine);

  @override
  void drive() {
    print('Vroom! I have ${engine.horsePower} horsepower in my engine.');
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  angel_container: ^1.0.0-alpha.12

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/angel_container.dart';
  
Version Uploaded Documentation Archive
1.0.0-alpha.12 Nov 8, 2018 Go to the documentation of angel_container 1.0.0-alpha.12 Download angel_container 1.0.0-alpha.12 archive
1.0.0-alpha.11 Nov 8, 2018 Go to the documentation of angel_container 1.0.0-alpha.11 Download angel_container 1.0.0-alpha.11 archive
1.0.0-alpha.10 Oct 22, 2018 Go to the documentation of angel_container 1.0.0-alpha.10 Download angel_container 1.0.0-alpha.10 archive
1.0.0-alpha.9 Aug 26, 2018 Go to the documentation of angel_container 1.0.0-alpha.9 Download angel_container 1.0.0-alpha.9 archive
1.0.0-alpha.8 Aug 21, 2018 Go to the documentation of angel_container 1.0.0-alpha.8 Download angel_container 1.0.0-alpha.8 archive
1.0.0-alpha.7 Aug 21, 2018 Go to the documentation of angel_container 1.0.0-alpha.7 Download angel_container 1.0.0-alpha.7 archive
1.0.0-alpha.6 Aug 21, 2018 Go to the documentation of angel_container 1.0.0-alpha.6 Download angel_container 1.0.0-alpha.6 archive
1.0.0-alpha.5 Aug 21, 2018 Go to the documentation of angel_container 1.0.0-alpha.5 Download angel_container 1.0.0-alpha.5 archive
1.0.0-alpha.4 Aug 21, 2018 Go to the documentation of angel_container 1.0.0-alpha.4 Download angel_container 1.0.0-alpha.4 archive
1.0.0-alpha.3 Aug 21, 2018 Go to the documentation of angel_container 1.0.0-alpha.3 Download angel_container 1.0.0-alpha.3 archive

All 13 versions...

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

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

  • Dart: 2.0.0
  • pana: 0.12.6

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/src/empty/empty.dart. (-1.49 points)

Analysis of lib/src/empty/empty.dart reported 3 hints:

line 66 col 17: Always override hashCode if overriding ==.

line 89 col 17: Always override hashCode if overriding ==.

line 99 col 17: Always override hashCode if overriding ==.

Fix lib/src/mirrors/reflector.dart. (-0.50 points)

Analysis of lib/src/mirrors/reflector.dart reported 1 hint:

line 163 col 17: Always override hashCode if overriding ==.

Maintenance suggestions

Package is pre-release. (-5 points)

Pre-release versions should be used with caution, their API may change in breaking ways.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
collection ^1.0.0 1.14.11
quiver ^2.0.0 2.0.1
Transitive dependencies
matcher 0.12.4
meta 1.1.6
path 1.6.2
stack_trace 1.9.3
Dev dependencies
test any