angel_container 1.0.0-alpha.10

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

container #

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

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

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';
  
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]
49
Health:
Code health derived from static analysis. [more]
55
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

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

  • Dart: 2.3.0
  • pana: 0.12.15

Platforms

Detected platforms: Flutter, web, other

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

Health issues and suggestions

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

Analysis of lib/src/empty/empty.dart failed with 2 errors:

line 50 col 13: Invalid constant value.

line 73 col 60: Invalid constant value.

Fix lib/angel_container.dart. (-1.49 points)

Analysis of lib/angel_container.dart reported 3 hints:

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

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

line 36 col 19: Use = to separate a named parameter from its default value.

Maintenance suggestions

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can 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.3
Transitive dependencies
matcher 0.12.5
meta 1.1.7
path 1.6.2
stack_trace 1.9.3
Dev dependencies
test any