angel_container 1.0.4

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

container #

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

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.

example/main.dart

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

  // 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) => t.drive());

  // 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.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:angel_container/angel_container.dart';
  
Version Uploaded Documentation Archive
1.0.4 Apr 17, 2019 Go to the documentation of angel_container 1.0.4 Download angel_container 1.0.4 archive
1.0.3 Apr 17, 2019 Go to the documentation of angel_container 1.0.3 Download angel_container 1.0.3 archive
1.0.2 Apr 17, 2019 Go to the documentation of angel_container 1.0.2 Download angel_container 1.0.2 archive
1.0.1 Apr 10, 2019 Go to the documentation of angel_container 1.0.1 Download angel_container 1.0.1 archive
1.0.0 Nov 30, 2018 Go to the documentation of angel_container 1.0.0 Download angel_container 1.0.0 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

All 18 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
48
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]
73
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/src/static/static.dart. (-1.99 points)

Analysis of lib/src/static/static.dart reported 4 hints:

line 13 col 18: Use = to separate a named parameter from its default value.

line 14 col 17: Use = to separate a named parameter from its default value.

line 15 col 21: Use = to separate a named parameter from its default value.

line 16 col 21: Use = to separate a named parameter from its default value.

Fix lib/src/container.dart. (-0.50 points)

Analysis of lib/src/container.dart reported 1 hint:

line 64 col 10: Don't explicitly initialize variables to null.

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.3
Transitive dependencies
matcher 0.12.5
meta 1.1.7
path 1.6.2
stack_trace 1.9.3
Dev dependencies
test any