dain 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • new54

[EAP] Dain

pub package license

A dynamic dependency injection framework for Dart developers.
The library is created inspired by "Koin". (Not all features are yet covered.)

Basic Usage #

1. Create interface & implementation class.

Let's create interface class.

abstract class ExampleService {
  void sayHello();
}

Next, create implementation class.
At this time, implementation class should extend interfaces.

class ExampleServiceImpl extends ExampleService {
  @override
  void sayHello() {
    print("Hello World!");
  }
}

2. Create module class & declaring dependencies.

class ExampleModule extends Module {
  @override
  List<Bean> register() {
    return [
      single<ExampleService>(() => ExampleServiceImpl()),
    ];
  }
}

3. Register modules & inject class.

void main() {
  Dain.start([
    ExampleModule(),
  ]);

  final exampleModel = Dain.inject<ExampleService>();
  exampleModel.sayHello(); // print "Hello World!"
}

Advanced #

[WIP]

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/example.dart

import 'package:dain/bean/bean.dart';
import 'package:dain/dain.dart';
import 'package:dain/module/module.dart';

void main() {
  Dain.start([
    ExampleModule(),
  ]);

  final exampleModel = Dain.inject<ExampleService>();
  exampleModel.sayHello(); // print "Hello World!"
}

//Interface class
abstract class ExampleService {
  void sayHello();
}

//Implementation class
class ExampleServiceImpl extends ExampleService {
  @override
  void sayHello() {
    print("Hello World!");
  }
}

//Bean registration class
class ExampleModule extends Module {
  @override
  List<Bean> register() {
    return [
      single<ExampleService>(() => ExampleServiceImpl()),
    ];
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  dain: ^0.0.5

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:dain/dain.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
13
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
54
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: Flutter, web, other

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

Health issues and suggestions

Document public APIs. (-1 points)

76 out of 76 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/bean/scoped.dart.

Run dartfmt to format lib/bean/scoped.dart.

Format lib/scope/scope.dart.

Run dartfmt to format lib/scope/scope.dart.

Format lib/scope/scope_resolver.dart.

Run dartfmt to format lib/scope/scope_resolver.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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test ^1.9.3