---
An pragmatic and flexible lightweight dependency injection library. This is a port of [Koin](https://github.com/InsertKoinIO/koin) for Dart projects.
Written in pure Dart, using functional resolution only: no code generation, no reflection.
| Package | Pub |
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| [koin](https://github.com/pbissonho/koin.dart/tree/master/packages/koin) | [![pub package](https://img.shields.io/pub/v/koin.svg)](https://pub.dev/packages/koin) |
| [koin_test](https://github.com/pbissonho/koin.dart/tree/master/packages/koin_test) | [![pub package](https://img.shields.io/pub/v/koin_test.svg)](https://pub.dev/packages/koin_test) |
| [koin_flutter](https://github.com/pbissonho/koin.dart/tree/master/packages/koin_flutter) | [![pub package](https://img.shields.io/pub/v/koin_flutter.svg)](https://pub.dev/packages/koin_flutter) |
| [koin_bloc](https://github.com/pbissonho/koin.dart/tree/master/packages/koin_bloc) | [![pub package](https://img.shields.io/pub/v/koin_bloc.svg)](https://pub.dev/packages/koin_bloc) |
| [koin_devtools](https://github.com/pbissonho/koin.dart/tree/master/packages/koin_devtools) | [![pub package](https://img.shields.io/pub/v/koin_devtools.svg)](https://pub.dev/packages/koin_devtools) |
## Why should I use Koin?
- Allows to dispose your objects at the moment that you are no longer using them.
- It does not depend on the Flutter.
* The core does not depend on Flutter, so it is possible to use it with any Dart application.
- Define in which scope a variable can be accessed.
* The koin scope allows you to define in which part of the widget tree a variable will be accessible
- Integration by default for [Bloc library](https://pub.dev/packages/bloc), but it can be easily used with any state management.
- Koin DevTools to inspect the state of your objects.
* Inspect the internal state of each object at any time on a Flutter page.
- Dependencies are instances only when needed.
* Its class is instant when used for the first time.
* Koin has a implementation of [Lazy](https://www.lordcodes.com/articles/the-power-of-lazy-properties-in-kotlin) by Kotlin to enhance this functionality.
- It is not invasive.
* Insert Koin in your project without changing the structure of your widgets.
- Facilitates dependency injection by constructor
* Using dependency injection by constructor you decrease the coupling and make the test easier.
* Makes it easy to know the dependencies of your components. Just look at your class's constructor to identify how dependencies it uses.
## Features
- Modules
- Scopes
- Singleton provider(definition)
- Factory provider(definition)
- Scoped provider(definition)
- Support to multiple bindings
- Support to named provider(definition)
- Easy testing
- Lazy inject
- Logging
- Support to parameter injection
- Integration by default for Bloc library
- DevTools for state inspection
## What Koin.dart is not?
It is not a state manager. Koin does not have any type of state management, use koin with any state manager.
## Table Of Contents
* [Quick Start](#Quick-Start)
* [Setup](#setup)
* [Getting Started](https://pbissonho.github.io/docs/start/getting-started/starting-koin)
* [Documentation References](https://pbissonho.github.io/docs/reference/koin-core/definitions)
* [Examples](#Examples)
## Roadmap
* Improve documentation
* Add more examples
* Example of use with Redux, Mobx and RxDart.
* Example with HTTP server frameworks.
* Create an external DevTools
* Add logger plugin for [logger](https://pub.dev/packages/logger)
## Quick Start
### Basic Setup
### Dart
```yaml
dependencies:
koin: ^[version]
```
### Flutter
```yaml
dependencies:
koin: ^[version]
koin_flutter: ^[version]
```
### Declare a Koin module
```dart
// Given some classes
class Bloc {
final Repository service;
Bloc(this.service);
get state => "Hello";
}
class Repository {}
// just declare your providers(definitions)
final myModule = Module()
// Declare a single provider(definition) for Bloc class
..single((s) => Bloc(s.get()))
// Declare a single provider(definition) for Repository class
..single((s) => Repository());
```
### Starting Koin
Use the startKoin() function to start Koin in your application.
In a Dart app:
```dart
void main(List