koin 0.12.0 koin: ^0.12.0 copied to clipboard
A pragmatic lightweight dependency injection framework for Dart projects.
Koin.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 | |
koin_test | |
koin_flutter |
Documentation 🚒 #
Ask a Question? 🚑 #
- Post your question on Stackoverflow - #koindart tag
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 #
- Arnaud Giuliani and all contributors to the original Koin version written in Kotlin.
Dependencies #
- Kt.dart port by Pascal Welsch
- Equatable created by Felix Angelov