koin 0.3.2+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

Koin.dart #

Build Status codecov

A pragmatic lightweight dependency injection framework. This is a port of Koin for Dart projects.

ExtensionsPub
koin_testpub package
koin_flutterpub package

Warning #

This port does not have all the koin features implemented yet, and what it already has is not fully tested. I do not recommend using it yet.

Get started #

Add dependency #

dependencies:
  koin: ^[version]

Features #

  • Pragmatic
  • Modules
  • Scopes
  • Singleton definition
  • Factory definition
  • Scoped definition
  • Support to multiple bindings
  • Support to named definition
  • Easy testing
  • Lazy inject
  • Logging
  • Support to injection parameters

0.3.2+3 #

  • Update readme

0.3.2+2 #

  • Update readme

0.3.2+1 #

  • Update description
  • Code improvements with pub.dev health suggestions

0.3.2+1 #

  • Update description
  • Code improvements with pub.dev health suggestions

0.3.2 #

  • Added NullParameterFoundException
  • Remove Analysis reports

0.3.1 #

  • Exported lazy class

0.3.0 #

  • Parameters of the definition functions configured as named
  • All documentation set to dart standards
  • More tests added
  • Lazy rewritten

0.2.0 #

  • Added Lazy inject

0.1.0 #

  • Initial version

example/example.dart

import 'package:koin/src/core/global_context.dart';
import 'package:koin/src/core/module.dart';

class Post {}

abstract class PostRepository {
  List<Post> getAll();
}

class RestPostRepository implements PostRepository {
  @override
  List<Post> getAll() {
    return [Post(), Post()];
  }
}

var postModule = Module()
  ..single<PostRepository>((s, p) => RestPostRepository());

void main() {
  var koin = startKoin((app) {
    app..module(postModule);
  }).koin;

  var postRepository = koin.get<PostRepository>();
}

Use this package as a library

1. Depend on it

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


dependencies:
  koin: ^0.3.2+3

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:koin/koin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
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]
75
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

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

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

line 108 col 11: This function has a return type of 'List

line 119 col 5: This function has a return type of 'S', but doesn't end with a return statement.

line 131 col 5: This function has a return type of 'S', but doesn't end with a return statement.

line 158 col 9: This function has a return type of 'Scope', but doesn't end with a return statement.

Fix lib/src/core/registry/bean_register.dart. (-0.50 points)

Analysis of lib/src/core/registry/bean_register.dart reported 1 hint:

line 233 col 18: This function has a return type of 'BeanDefinition', but doesn't end with a return statement.

Format lib/src/core/global_context.dart.

Run dartfmt to format lib/src/core/global_context.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
equatable ^1.0.0 1.0.3
kt_dart ^0.6.2 0.6.2 0.7.0-dev.4
path ^1.6.0 1.6.4
Transitive dependencies
collection 1.14.12
meta 1.1.8
Dev dependencies
pedantic ^1.8.0
test ^1.6.0
test_coverage ^0.3.0