FLUTTER ECOSYSTEM

ditclear/dartin

Flutter開発者向けの実用的で軽量な依存関係注入フレームワーク。

dartin のプロジェクト画像
Stars
42
Forks
4
最終プッシュ(UTC)
2019/12/02
プロジェクト状態
公開中
D•IT•CLEAR GitHub avatar
GITHUB User

D•IT•CLEAR ↗

Adventure of my LifeTime

@freeShanghai.China
言語Dart

技術トピック

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 2 件
  • flutter{"sdk":"flutter"}
  • flutter_test開発用{"sdk":"flutter"}

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

README を開く / 閉じる

dartin

https://img.shields.io/badge/build-passing-brightgreen.svg https://img.shields.io/badge/pub-v0.1.0-blue.svg https://img.shields.io/badge/support-dart%7Cflutter-red.svg

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.1.5
  
Key methods
  • single: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:get T from dartIns by T.runtimeType and params

more informations see dartin.dart.

Getting Started
  1. 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([
  single<GithubRepo>(({params}) => GithubRepo(get<GithubService>())),
]);

final remoteModule = Module([
  single<GithubService>(({params}) => GithubService()),
]);

final appModule = [viewModelModule, repoModule, remoteModule];

  1. Start dartin
void main() {
  startDartIn(appModule);
  runApp(MyApp());
}
  1. 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