service_registry 2.0.1

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

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]
42
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, web, other

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

Maintenance suggestions

The description is too long. (-10 points)

Search engines will display only the first part of the description. Try to keep it under 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