service_registry 2.0.1

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

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>(new CounterService());

  var counterService = ServiceRegistry.getService<CounterService>();
  counterService.increment();
  counterService.increment();
  print(ServiceRegistry.getService<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>().count); // 1
}


TODO #

  • [] add coverage reporting
  • [] check service type with the given register type

[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>(new CounterService());

  var counterService = ServiceRegistry.getService<CounterService>();
  counterService.increment();
  counterService.increment();
  var currentCount = ServiceRegistry.getService<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>().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: ^2.0.1

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:service_registry/service_registry.dart';
  
Version Uploaded Documentation Archive
2.0.1 Sep 3, 2018 Go to the documentation of service_registry 2.0.1 Download service_registry 2.0.1 archive
2.0.0 Sep 3, 2018 Go to the documentation of service_registry 2.0.0 Download service_registry 2.0.0 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]
48
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:service_registry/service_registry.dart.

Health suggestions

Fix lib/service_registry.dart. (-2.48 points)

Analysis of lib/service_registry.dart reported 5 hints:

line 3 col 1: Prefer using /// for doc comments.

line 30 col 3: Prefer using /// for doc comments.

line 42 col 3: Prefer using /// for doc comments.

line 53 col 3: Prefer using /// for doc comments.

line 62 col 3: Prefer using /// for doc comments.

Maintenance suggestions

The description is too long. (-10 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <3.0.0
Dev dependencies
coverage ^0.12.2
test ^1.3.0