angel_container 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

container #

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

1.1.0 #

  • pedantic lints.
  • Add ThrowingReflector, which throws on all operations.
  • EmptyReflector uses Object instead of dynamic as its returned type, as the dynamic type is (apparently?) no longer a valid constant value.
  • registerSingleton now returns the provided object.
  • registerFactory and registerLazySingleton now return the provided function f.

1.0.4 #

  • Slight patch to prevent annoying segfault.

1.0.3 #

  • Added Future support to Reflector.

1.0.2 #

  • Added makeAsync<T>.

1.0.1 #

  • Added hasNamed.

1.0.0 #

  • Removed @GenerateReflector.

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.


import 'dart:async';

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

Future<void> main() async {
  // Create a container instance.
  var container = Container(const MirrorsReflector());

  // Register a singleton.

  // 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>();

  // You can also resolve injections asynchronously.
  container.registerFactory<Future<int>>((_) async => 24);
  print(await container.makeAsync<int>());

  // Asynchronous resolution also works for plain objects.
  await container.makeAsync<Truck>().then((t) =>;

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

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

  // Should print the same.

  // 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.

  // However, calling `make<Engine>` will return the Engine singleton we created above.

abstract class Truck {
  void drive();

class Engine {
  final int horsePower;


class _TruckImpl implements Truck {
  final Engine engine;


  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:

  angel_container: ^1.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub 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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21


Detected platforms: Flutter, web, other

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


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
collection ^1.0.0 1.14.12
quiver ^2.0.0 2.1.2+1
Transitive dependencies
matcher 0.12.6
meta 1.1.8
path 1.6.4
stack_trace 1.9.3
Dev dependencies
pedantic ^1.0.0
test ^1.0.0