パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v5.1.0

scope

依存関係の挿入(制御の逆転)ライブラリ。ネストされたスコープと同一型の複数の値をサポートしています。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
25.4万
いいね数
14
Pub ポイント
150

パッケージをインストール

flutter pub add scope

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Scope は、Flutter および Dart 向けの依存関係挿入(制御の逆転)ライブラリであり、構造的で階層的な依存関係管理を可能にします。ネストされたスコープをサポートして依存関係を分離でき、同じ型の複数のインスタンスを許可するため、モジュール化アプリに最適です。明確な API デザインと最小限のボイラープレートにより、アプリ内のさまざまな部分での状態管理やサービスのインスタンス化が簡単になります。Android、iOS、Web、macOS、Windows、Linux などの主要プラットフォームすべてでシームレスに動作します。

用途

  • モジュール型アプリケーションアーキテクチャ
  • 分離された依存関係を使用したテスト
  • 共有およびスコープ付きサービスの管理
  • マルチインスタンスサービス処理
  • クロスプラットフォームアプリ開発

主な機能

  • ネストされたスコープのサポート
  • 同じ型の複数の値
  • 最小限のボイラープレート
  • Platform-agnostic
  • 洗練された API デザイン
  • 既存コードとの簡単な統合

適している対象

  • 大規模なFlutterアプリ
  • テスト可能なアーキテクチャ
  • マイクロサービス風のアプリモジュール
  • 依存関係の分離が必要なチーム
  • 複雑なDIフレームワークを避けたい開発者

注意事項

  • 新規ユーザーの習得曲線
  • 成熟した代替品と比べてドキュメントが限られている
  • 複雑な依存関係ツリーを持つアプリに最適

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Scope

Scope provides Inversion of Control using the dependency injection (DI) pattern for Dart applications.

Scope allows you to inject values into a scope and then 'use' those dependencies from any method (or constructor) called within that scope.

Scope is incredibly easy to use with no additional plumbing required.

Scope is not a replacement for the likes of Provider. Provider does dependency injection for your BuildContext whilst Scope provides DI for your call stack.

For Java developers Scope provides similar functionality to thread local variables.

Scope supports nested scopes; overload or add additional values at each level.

Supporters

Scope is supported by OnePub the private Dart package repository.

https://onepub.dev

The best way to understand Scope is with an example:

import 'package:scope/scope.dart';
import 'package:money2/money2.dart';

const ageKey = ScopeKey<int>();
const heightKey = ScopeKey<int>();
const incomeKey = ScopeKey<Money>();
const countKey = ScopeKey<int>();

void main() async {
    /// create a Scope
    final scope = Scope()
    
    /// inject values
    ..value<int>(ageKey, 18)
    ..value<int>(heightKey, 182) // centimetres
    /// single value from factory method
    ..single<Money>(incomeKey, () => calcIncome)
    /// sequence of values from factory method.
    ..sequence<int>(countKey, () => tracker);
    
    /// run some code within the Scope
    await scope.run(() async => a();
}
void a() {
    print('Your height is ${use(heightKey)}');
    printRealWorth();
}

/// `use` the injected values
void printRealWorth() {
    print('You are the ${use(countKey)} person to ask');
    print('You are ${use(ageKey)} years old');
    print('You earn ${use(incomeKey} per hour.');
}

Money calcIncome() {
    final age = use(ageKey);
    if (age < 18) return Money.parse(r'$10.00');

    return Money.parse(r'$20.00');
}

var count = 0;
int tracker()
{
    return count++;
}

See the Scope documentation at:

https://scope.onepub.dev

The best practice guide is worth a read:

https://scope.onepub.dev/guides/best-practice

Authors: 
Philipp Schiffmann <philippschiffmann93@gmail.com>
S. Brett Sutton

Scope is a reimagining of Philipp's zone_id package. All credit goes to Phillipp's original implementation without which Scope wouldn't exist.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト