Search packages, repositories and app categories

GitHub repositoryonepub-dev/scope

scope

Dependency injection for Dart applications.

scope project cover
Stars
3
Forks
1
Last push (UTC)
Apr 5, 2026
Project status
Active

Original README

English project snapshot. Visit GitHub for the latest content.

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.

OnePub GitHub avatar
GitHub author

OnePub ↗

LanguagesDart

Packages published by this repository

Dependencies used

Dependency list 4 items

  • meta^1.1.7
  • lint_hardDevelopment^6.2.1
  • money2Development^6.0.5
  • testDevelopment^1.6.7

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗