service_registry 1.0.2 copy "service_registry: ^1.0.2" to clipboard
service_registry: ^1.0.2 copied to clipboard

outdatedDart 1 only

A Service registry for dart.

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
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A Service registry for dart.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on service_registry