service_registry 1.0.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 27

service_registry

Version Build Status

A service registry for doing IoC on Dart.

Motivation

Basically because I did not know how to properly handle singletons in a flutter application, so I did this for a project and felt that I could share.

Usage

import 'package:service_registry/service_registry.dart';

class CounterService {
  int count = 0;

  increment() {
    count++;
  }

  decrement() {
    count--;
  }
}

void main() {
  ServiceRegistry.registerService<CounterService>(CounterService, new CounterService());

  var counterService = ServiceRegistry.getService<CounterService>(CounterService);
  counterService.increment();
  counterService.increment();
  print(ServiceRegistry.getService<CounterService>(CounterService).count); // 2

  counterService.decrement();

  // Actually you don't need to add the <CounterService> part, but it's handy for tools to know the type and provide code completion
  print(ServiceRegistry.getService<CounterService>(CounterService).count); // 1
}


TODO

  • [] add coverage reporting
  • [] check service type with the given register type
  • [] somehow make it not necessary to pass the generic <ServiceType> when using ServiceRegistry.getService()

[1.0.3] - 29-03-2018.

  • Adding hasService method

[1.0.2] - 29-03-2018.

  • Better Documentation
  • Better output on example.dart
  • Trying to get a better scoring on dartpub ¯_(ツ)_/¯

[1.0.1] - 28-03-2018.

  • Simple working version with static implementation.

example/example.dart

import 'package:service_registry/service_registry.dart';

class CounterService {
  int count = 0;

  increment() {
    count++;
  }

  decrement() {
    count--;
  }
}

void main() {
  ServiceRegistry.registerService<CounterService>(CounterService, new CounterService());

  var counterService = ServiceRegistry.getService<CounterService>(CounterService);
  counterService.increment();
  counterService.increment();
  var currentCount = ServiceRegistry
      .getService<CounterService>(CounterService)
      .count;
  print("CounterService current count [$currentCount]"); // 2

  counterService.decrement();

  // Actually you don't need to add the <CounterService> part, but it's handy for tools to know the type and provide code completion
  currentCount = ServiceRegistry
      .getService<CounterService>(CounterService)
      .count;
  print("CounterService current count [$currentCount]"); // 1
}

Use this package as a library

1. Depend on it

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


dependencies:
  service_registry: ^1.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:service_registry/service_registry.dart';
  
Version Uploaded Documentation Archive
1.0.3 Mar 29, 2018 Go to the documentation of service_registry 1.0.3 Download service_registry 1.0.3 archive
1.0.2 Mar 29, 2018 Go to the documentation of service_registry 1.0.2 Download service_registry 1.0.2 archive
1.0.1 Mar 28, 2018 Go to the documentation of service_registry 1.0.1 Download service_registry 1.0.1 archive
1.0.0 Mar 28, 2018 Go to the documentation of service_registry 1.0.0 Download service_registry 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
27
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <2.0.0