koin 0.12.0 copy "koin: ^0.12.0" to clipboard
koin: ^0.12.0 copied to clipboard

outdated

A pragmatic lightweight dependency injection framework for Dart projects.

Koin.dart #

Koin.dart

build codecov Star on Github style: effective dart


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

Written in pure Dart, using functional resolution only: no proxy, no code generation, no reflection, no Flutter context.

Koin is a DSL, a light container and a pragmatic API

Package Pub
koin pub package
koin_test pub package
koin_flutter pub package

Documentation 🚒 #

Ask a Question? 🚑 #

Reporting issues 💥 #

Found a bug on a specific feature? Open an issue on Github issues

Contribute 🛠 #

Want to help or share a proposal about Koin? problem on a specific feature?

  • Open an issue to explain the issue you want to solve Open an issue
  • After discussion to validate your ideas, you can open a PR or even a draft PR if the contribution is a big one Current PRs

Setup #

Add dependency #

dependencies:
  koin: ^[version]

Flutter #

dependencies:
  koin: ^[version]
  koin_fluter: ^[version]

Quick Start #

Declare a Koin module #

// Given some classes 
class Controller {
  final BusinessService service;

  Controller(this.service);
}

class BusinessService {}

// just declare it
var myModule = Module()
  ..single((s) => Controller(s.get()))
  ..single((s) => BusinessService());

Starting Koin #

Use the startKoin() function to start Koin in your application.

In a Dart app:

void main(List<String> args) {
    startKoin((app){
      app.module(myModule);
    });
  }

In an Flutter app:

void main() {
  startKoin((app) {
    app.printLogger(level: Level.debug);
    app.module(homeModule);
  });
  runApp(MyApp());
}

Injecting dependencies #

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    // Get a dependency
    var controller = get<Controller>();
    return Container(
      child: Text("${controller.toString()}"),
    );
  }
}

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

Maintainers #

Credits #

Dependencies #

59
likes
0
pub points
58%
popularity

Publisher

unverified uploader

A pragmatic lightweight dependency injection framework for Dart projects.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

equatable, kt_dart

More

Packages that depend on koin