搜尋套件、儲存庫與 APP 分類

套件詳情v0.1.5

dartin

一個實用的輕量級依賴注入框架,專為Flutter開發者設計。

近 30 天下載
100
喜歡數
8
Pub 分數
40

安裝套件

flutter pub add dartin

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Dartin 是一個輕量級、實用的依賴注入框架,專為 Flutter 開發者設計。它透過提供一種乾淨且高效的方式來註冊和解析依賴項,簡化了 Flutter 應用中的依賴管理。Dartin 具有最少的样板程式碼和直覺的語法,可輕鬆整合到現有專案中,而不會增加複雜性。它支援從簡單到進階的各種使用情境,非常適合從小型原型到大型應用的各類應用。該框架強調開發者體驗與效能,確保快速啟動時間與可靠的依賴解析。

適用情境

  • 簡單的應用程式依賴管理
  • 大規模 Flutter 應用程式架構
  • 使用模擬依賴項進行測試
  • 快速原型設計
  • 模組化應用開發
  • 狀態管理整合

主要特色

  • 最小化樣板程式碼
  • 輕鬆設定與設定
  • 支援單例與暫時實例
  • 內建測試支援
  • 輕量級佔用
  • 直觀的 API 設計

適合對象

  • Flutter 初學者尋找簡單的依賴注入
  • 需要輕量級依賴注入的資深開發人員
  • 構建模組化 Flutter 應用的團隊
  • 需要可測試依賴結構的專案
  • 具有不斷變化的依賴需求的應用程式

使用建議

  • 與較大的框架相比,文件資料有限
  • 無內建狀態管理
  • 不適用於非常複雜的依賴關係圖
  • 社群規模小於其他替代方案
  • 高級功能需要手動設定

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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.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

所屬分類

原始碼儲存庫

使用此套件的專案