dart_ioc 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 48

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>()  
}

See also examples for detailed examples.

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 with support for types, singletons, factory methods and merging of containers.

v1.0.1 - 2020-01-12 #

Docs #

  • maintenance [265425e]

v1.0.0 - 2019-11-16 #

Feature #

  • Initial Release [38974a5]

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: ^1.0.1

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]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.9+1

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native of android

Because of the import of dart:mirrors via the import chain package:dart_ioc/dart_ioc.dart->package:dart_ioc/src/container.dart->package:dart_ioc/src/type_validator.dart->dart:mirrors

Package not compatible with runtime flutter-native of ios

Because of the import of dart:mirrors via the import chain package:dart_ioc/dart_ioc.dart->package:dart_ioc/src/container.dart->package:dart_ioc/src/type_validator.dart->dart:mirrors

Package not compatible with runtime flutter-native of linux

Because of the import of dart:mirrors via the import chain package:dart_ioc/dart_ioc.dart->package:dart_ioc/src/container.dart->package:dart_ioc/src/type_validator.dart->dart:mirrors

Package not compatible with runtime flutter-native of macos

Because of the import of dart:mirrors via the import chain package:dart_ioc/dart_ioc.dart->package:dart_ioc/src/container.dart->package:dart_ioc/src/type_validator.dart->dart:mirrors

Package not compatible with runtime flutter-native of windows

Because of the import of dart:mirrors via the import chain package:dart_ioc/dart_ioc.dart->package:dart_ioc/src/container.dart->package:dart_ioc/src/type_validator.dart->dart:mirrors

Package not compatible with runtime flutter-web of web

Because of the import of dart:mirrors via the import chain package:dart_ioc/dart_ioc.dart->package:dart_ioc/src/container.dart->package:dart_ioc/src/type_validator.dart->dart:mirrors

Package not compatible with runtime native-aot

Because of the import of dart:mirrors via the import chain package:dart_ioc/dart_ioc.dart->package:dart_ioc/src/container.dart->package:dart_ioc/src/type_validator.dart->dart:mirrors

Package not compatible with runtime web

Because of the import of dart:mirrors via the import chain package:dart_ioc/dart_ioc.dart->package:dart_ioc/src/container.dart->package:dart_ioc/src/type_validator.dart->dart:mirrors

Health suggestions

Format lib/src/container.dart.

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

Maintenance issues and suggestions

Documentation URL doesn't exist. (-10 points)

At the time of the analysis the documentation field https://svogelsang.gitlab.io/dart_ioc was unreachable.

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