Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Panthro/ServiceRegistry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

10 Commits

Repository files navigation

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

About

A service registry (IoC) for Dart

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /