dartin 0.1.0
dartin #
A pragmatic lightweight dependency injection framework for Flutter developers.
A light container inspired by flutter-provide and koin.
more examples see mvvm_flutter.
Setup #
dependencies:
dartin: ^0.0.1
Key methods #
-
single:Creates a provider with the value provided to it.
-
lazy:Creates a provider which will initialize using the [_DartInFunction] the first time the value is requested.
-
factory:Creates a provider that provides a new value using the [_DartInFunction] for each requestor of the value.
-
**inject
more informations see dartin.dart.
Getting Started #
-
declare dartin modules #
//scope should always be initialized as a static const and passed around.
const test = DartInScope('test');
final viewModelModule = Module([
factory<HomeProvide>(({params}) => HomeProvide(params.get(0), get<GithubRepo>())),
])
..withScope(test , [
///other scope
factory<HomeProvide>(({params}) => HomeProvide(params.get(0), get<GithubRepo>())),
]);
final repoModule = Module([
lazy<GithubRepo>(({params}) => GithubRepo(get<GithubService>())),
]);
final remoteModule = Module([
single<GithubService>(GithubService()),
]);
final appModule = [viewModelModule, repoModule, remoteModule];
-
Start dartin #
void main() {
startDartIn(appModule);
runApp(MyApp());
}
-
inject #
//default
final service = inject<GithubService>();
//pass parameters
final test = inject<HomeProvide>(params: ['title']);
//different scope
final test = inject<HomeProvide>(scope:test,params: ['title']);
DartIn is easy to use, and still improving.
🍺 welcome to fork and pull request。
Article #
【Medium】:DartIn:A pragmatic lightweight dependency injection framework for Flutter developers
【简书】:为Flutter而生的轻量级依赖检索容器—DartIn
【掘金】:为Flutter而生的轻量级依赖检索容器—DartIn
Licence #
BSD
[0.1.0] - 2019.03.23
- publish version 0.1.0
- add example
[0.0.1] - 2019.03.22
- publish version 0.0.1
import 'package:dartin/dartin.dart';
import 'dummy.dart';
//constant scope
const other = DartInScope('other');
const params = DartInScope('params');
final dummy1 = Dummy(1);
final dummy2 = Dummy(2);
//define module
final m = Module([
single<Dummy>(dummy1),
])
..withScope(other, [
single<Dummy>(dummy2),
])
..withScope(params, [
factory<Dummy>(({params}) => Dummy(params.get(0))),
]);
main() {
startDartIn([m]);
//default
final value1 = inject<Dummy>();
//scope
final value2 = inject<Dummy>(scope: other);
//parameters
final value3 = inject<Dummy>(scope: params, params: [3]);
}
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
dartin: ^0.1.0
2. Install it
You can install packages from the command line:
with Flutter:
$ flutter pub get
Alternatively, your editor might support 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:dartin/dartin.dart';
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
82
|
Health:
Code health derived from static analysis.
[more]
|
100
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
100
|
Overall:
Weighted score of the above.
[more]
|
91
|
We analyzed this package on Nov 23, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.6.1
- pana: 0.12.21
- Flutter: 1.9.1+hotfix.6
Platforms
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Health suggestions
Format lib/dartin.dart
.
Run flutter format
to format lib/dartin.dart
.
Dependencies
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.1.0 <3.0.0 | ||
flutter | 0.0.0 | ||
Transitive dependencies | |||
collection | 1.14.11 | 1.14.12 | |
meta | 1.1.7 | 1.1.8 | |
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test |