Package selection guidance compiled from public package information, community data, and project usage.
Koin is a lightweight, pragmatic dependency injection (DI) framework for Dart projects, designed to simplify the management of dependencies in applications. It provides a clean and concise syntax for defining and injecting dependencies, promoting modularity and testability. Koin supports both functional and class-based components, enabling developers to easily manage singletons, factories, and scoped instances. With minimal boilerplate, it integrates seamlessly into Flutter and other Dart applications, making it ideal for scalable and maintainable codebases.
Use cases
Managing application-wide dependencies
Testing with mock dependencies
Modularizing large-scale applications
Simplifying service instantiation
Supporting different environments (dev, prod)
Enabling clean separation of concerns
Key features
Minimal boilerplate
Functional and class-based definitions
Singleton, factory, and scoped bindings
Easy testing with dependency replacement
Built-in support for lazy initialization
Lightweight and fast runtime
Suitable for
Flutter developers seeking simple DI
Projects requiring modular architecture
Teams prioritizing testability
Applications with complex dependency graphs
Developers wanting a lightweight alternative to larger DI frameworks
Considerations
Limited documentation compared to mature frameworks
Smaller community size
No built-in state management
Not suitable for very large enterprise applications without customization
Requires understanding of DI concepts for optimal use
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
Koin.dart
An pragmatic and flexible lightweight dependency injection library. This is a port of Koin for Dart projects.
Written in pure Dart, using functional resolution only: no code generation, no reflection.
// Given some classes classBloc{
finalRepository service;
Bloc(this.service);
get state => "Hello";
}
classRepository{}
// 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.