dart_ioc 0.0.1-dev

  • Readme
  • Changelog
  • Example
  • Installing
  • new46

pipeline status coverage report

A simple IoC Container for Dart.

Usage #

A simple usage example:

import 'package:dart_ioc/dart_ioc.dart';

main() {
  var container = new Container()
    .register<A>
    .registerSingleton(Stream.value(100));

  var stream = container.resolve<Stream>()  
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Change Log for dart_ioc #

An IoC container implementation for dart and flutter.

0.0.1-dev #

  • Initial version
  • Registration of singletons.
  • Registration of singetons created on first usage.
  • Registrations of abstract types.
  • Registration of types.
  • Resolving types.
  • Merging containers.

This CHANGELOG.md was generated with Changelog for Dart

example/dart_ioc_example.dart

import 'package:dart_ioc/dart_ioc.dart';

abstract class A {
}

class B extends A {
}

main() {

  var containerWithSingletons = Container()
  // register singleton instance
    .registerSingleton('Hello World')
  // register singleton instantiated on first resolve using a factory method.
    .registerSingletonLazy<Stream>(() => Stream.value(100))
  // register singleton instantiated on first resolve using a factory method.
    .registerSingletonLazy<B>();

  String helloWorld = containerWithSingletons.resolve<String>();  
  print(helloWorld); // prints out 'Hello World'

  var containerWithTypes = Container()
  // register type.
    .registerType<B>()
  // register type with factory method.
    .registerType(() => 'Hello World');

  helloWorld = containerWithTypes.resolve<String>();  
  print(helloWorld); // prints out 'Hello World'

  var containerWithBaseTypes = Container()
  // register type as base type.
    .register<A,B>();

  B b = containerWithBaseTypes.resolve<A>();  
  print(b); // prints out 'Instance of 'B''

  // merge containers
  Container container1 = Container().registerType(() => 'Hello World');
  Container container2 = Container().registerType(() => 100);

  print(container1.merge(container2).resolve<int>()); // prints out 100
}

Use this package as a library

1. Depend on it

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


dependencies:
  dart_ioc: ^0.0.1-dev

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_ioc/dart_ioc.dart';
  
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]
78
Overall:
Weighted score of the above. [more]
46
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

Platforms

Detected platforms: web, other

Primary library: package:dart_ioc/dart_ioc.dart with components: mirrors.

Health suggestions

Format lib/src/container.dart.

Run dartfmt to format lib/src/container.dart.

Format lib/src/registration_exception.dart.

Run dartfmt to format lib/src/registration_exception.dart.

Format lib/src/resolve_exception.dart.

Run dartfmt to format lib/src/resolve_exception.dart.

Format lib/src/type_validator.dart.

Run dartfmt to format lib/src/type_validator.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-7 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

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 >=2.5.0 <3.0.0
Dev dependencies
build_runner ^1.6.2
build_web_compilers ^2.0.0
pedantic ^1.8.0
test ^1.6.0
test_coverage ^0.3.0