boar_locator 0.0.2 copy "boar_locator: ^0.0.2" to clipboard
boar_locator: ^0.0.2 copied to clipboard

Lightweight service locator for managing synchronous and asynchronous dependencies in Dart.

example/main.dart

import 'package:boar_locator/boar_locator.dart';

class ApiService {
  ApiService(this.baseUrl);

  final String baseUrl;
}

class DatabaseService {
  Future<void> initialize() async {
    await Future.delayed(const Duration(seconds: 2), () => {});
  }
}

void main() async {
  final locator = BoarLocator()..register(ApiService('https://api.example.com'))
    ..registerAsync<DatabaseService>(() async {
    final dbService = DatabaseService();
    await dbService.initialize();
    return dbService;
  });

  final apiService = locator.get<ApiService>();

  final dbService = await locator.getAsync<DatabaseService>();

}
1
likes
160
points
91
downloads

Publisher

verified publishercontributors.info

Weekly Downloads

Lightweight service locator for managing synchronous and asynchronous dependencies in Dart.

Homepage
Repository (GitHub)
View/report issues

Topics

#service-locator #dependency-management #service-registration #service-retrieval #lazy-initialization

Documentation

API reference

License

MIT (license)

More

Packages that depend on boar_locator