搜索插件、代码仓与 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

所属分类

源码仓库

使用此插件的项目