ioc_annotation 1.0.1 ioc_annotation: ^1.0.1 copied to clipboard
Quickly generate IoC singleton objects through annotations.
IoC Annotation #
Quickly generate IoC singleton objects through annotations.
Installation #
# pubspec.yaml
dependencies:
ioc_annotation: ^1.0.0
dev_dependencies:
build_runner:
Usage #
- Use
@IoC
to mark classes that need to be instantiated.
// person.dart
abstract class Person {
hello();
}
// Student.dart
import 'package:ioc_annotation/ioc_annotation.dart';
import 'package:test_demo/person.dart';
@IoC()
class Student implements Person {
@override
hello() {
print('hello');
}
}
- Use
@IoCInstance
to mark the single instance that needs to be generated.
// services.dart
import 'package:ioc_annotation/ioc_annotation.dart';
@IoCInstance()
abstract class Services {}
- Execute this command.
flutter pub run build_runner build
- Automatically generated IoC instances.
// services.ioc.dart
class Services {
/// ....
}