service_registry 1.0.3

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

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
}

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or 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
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

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
98 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
49
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

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

Suggestions

  • The description is too long.

    Search engines will display only the first part of the description. Try to keep it under 180 characters.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run dartfmt to format lib/service_registry.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <2.0.0
Dev dependencies
coverage ^0.7.0
dart_codecov_generator ^0.4.0
test ^0.12.0