패키지, 저장소 및 앱 카테고리 검색

패키지 상세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 설계
  • 기존 코드와의 간편한 통합

적합한 대상

  • 대규모 플러터 앱
  • 테스트 가능한 아키텍처
  • 마이크로서비스 유사 애플리케이션 모듈
  • 의존성 격리가 필요한 팀
  • 복잡한 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 개

소스 저장소

이 패키지를 사용하는 프로젝트