dime 0.2.0

  • README.md
  • Example
  • Installing
  • Versions
  • 70

Dime is Dart based Dependency Injection framework.

Dime allows to create modules and inject based on interfaces, provides way to specify factory methods and tag based same type instances. Support for multiple modules and scopes with Closable interface to cleanup resources.

Get it from pub page: Pub dime page

Note: All examples below are from example file file. Go there for high level view.

Usage #

A simple usage example:

import 'package:dime/dime.dart';

void main() {
  /// Service Module does include details how to create the objects.   
  MyTitleService titleService = Dime.inject();

Setup #

Add package dependency to pubspec.yaml: #

   dime: ^0.2.0

Define module: #

Create a module and how it creates its dependencies:

class MyModule  extends BaseAppInjectorModule {
    void updateInjections() {
        /// define injection factories - below for examples      

Below are examples that can be used inside updateInjections method.

Singleton per type #

Inject single value by its class type:


Inject singleton value by implementing interface:


Singleton per type with tag #

Inject single value by its class type:

  addSingle(MyTitleService(), tag: "home-title");
  addSingle(MyTitleService(), tag: "details-title");

Inject singleton value by implementing interface:

  addSingle<TitleService>(MyTitleService(), tag: "home-title");

Creator on-demand injection, it uses type of Creator #

This is creator - which will create an object at time of injection.

typedef T Creator<T>(String tag);

The Creator provides optional String tag that may be used to create the tagged instance.

addCreator<TextService>((tag) =>
        MyTitleService(title: "Test title: $tag: now: ${DateTime.now()}"));

Creator on-demand injection with singleton storage - delayed singleton. #

Similar to above example with addCreator, however created instance will be cached per tag.


Create your own factory. #

You can always create your own factory by extending InjectFactory<T> and add those to the module.

 addFactory(MyTooltipService, MyCustomFactory());

Note: There are some other Factories already provided to be used - like:

  • InjectTagFactory for create method with a Tag
  • TaggedSingletonInjectFactory - for tagged singletons with Closeable interface
  • SingleInjectFactory - single inject factory with Closable interface

Add modules to the scope (global too) #

You can add modules to the main global scope of Dime or into the opened scopes. When a scope closes all modules in that scope will also close (clean up) by calling each of its Closeable factory close() method to cleanup resources.

Add Module to Global Dime scope. #


Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.2.0 - Bug fix #

  • added same module injection visible to next injections

0.1.1 - Scopes updates #

  • allow override module's instances for a types.
  • Unit tests update

0.1.0 - initial release #

  • Dependency Injection with global scope.
  • Inject with modules and sub-scopes's modules.
  • Support for modules and scopes.
  • Creator types, on demand injection
  • Ability to add singletons and singleton of same type per tag.
  • Closable types will be properly disposed when closing scopes


import 'package:dime/dime.dart';
import 'package:fimber/fimber.dart';

import '../test/common.dart';

main() {
  Fimber.i("Started app");
  Fimber.i("Installed module");
  var scope = DimeScope("test");

  MyTitleService titleService = Dime.inject();

  MyTitleService titleService2 = Dime.inject(tag: "Test tag");

  var creatorService = Dime.inject<TextService>();

  creatorService = Dime.inject<TextService>(tag: "TEST TAG A");

  var scopeTitle = Dime.inject<MyTitleService>();

  scopeTitle = scope.inject<MyTitleService>();

  var tooltip = Dime.inject<MyTooltipService>();

  var scopeDescription = scope.inject<MyDescriptionService>();

  Dime.closeScope(scope: scope);

  scopeDescription = scope.inject<MyDescriptionService>();

class ScopeModule extends BaseDimeModule {
  void updateInjections() {
    addSingle(MyTitleService(title: "test scope service"));

class ServiceModule extends BaseDimeModule {
  void updateInjections() {
    addSingle(MyTitleService(title: "second title"), tag: "Test tag");
    addSingleByCreator((tag) => MyDescriptionService());
    addCreator<TextService>((tag) =>
        MyTitleService(title: "Test title: $tag: now- ${DateTime.now()}"));
    addFactory(MyTooltipService, MyCustomFactory());

class MyCustomFactory extends InjectFactory<TextService> {
  TextService create() {
    return MyTooltipService(tooltip: "My custom factory tooltip");

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dime: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:dime/dime.dart';
Version Uploaded Documentation Archive
0.2.0 Mar 28, 2019 Go to the documentation of dime 0.2.0 Download dime 0.2.0 archive
0.1.1 Mar 23, 2019 Go to the documentation of dime 0.1.1 Download dime 0.1.1 archive
0.1.0 Mar 20, 2019 Go to the documentation of dime 0.1.0 Download dime 0.1.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14


Detected platforms: Flutter, other

Primary library: package:dime/dime.dart with components: io.

Health suggestions

Format lib/src/dime_base.dart.

Run dartfmt to format lib/src/dime_base.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
fimber ^0.1.11 0.1.11 0.2.0
Dev dependencies
pedantic ^1.0.0
test ^1.0.0