fang 0.0.2
fang: ^0.0.2 copied to clipboard
A lightweight, zero-boilerplate service locator for Dart. Originally built for nyxx bot development.
example/fang_example.dart
import 'dart:async';
import 'dart:io';
import 'package:fang/fang.dart';
final class CustomClient {
const CustomClient();
String doA() => 'a';
Future<int> doB() => Future<int>.value(2);
}
Future<void> main(final List<String> args) async {
/// Imagine we have a client for something (http, database, device ...)
const CustomClient customClient = CustomClient();
/// We hold it between our fangs
Fang.bite(customClient);
/// Calling the singleton from Fang from somewhere else
Timer.run(() async {
print(await Fang.hunt<CustomClient>().doB());
exit(0);
});
}