mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-23 21:13:35 +00:00
feat: implement generator di module
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
import 'package:cherrypick_annotations/cherrypick_annotations.dart';
|
||||
|
||||
part 'foo.cherrypick_injectable.g.dart';
|
||||
|
||||
@Injectable()
|
||||
class Foo {
|
||||
late final String field;
|
||||
}
|
||||
|
||||
// где-то в main:
|
||||
void iniFoo() {
|
||||
$initCherrypickGenerated();
|
||||
// ... остальной код
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
import 'package:cherrypick_annotations/cherrypick_annotations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'use_case.dart';
|
||||
|
||||
part 'my_home_page.cherrypick_injectable.g.dart';
|
||||
|
||||
@Injectable()
|
||||
class MyHomePage extends StatelessWidget {
|
||||
late final UseCase useCase;
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import 'package:cherrypick_annotations/cherrypick_annotations.dart';
|
||||
|
||||
part 'my_service.cherrypick_injectable.g.dart';
|
||||
|
||||
@Injectable()
|
||||
class MyService {}
|
||||
|
||||
// где-то в main:
|
||||
void init() {
|
||||
$initCherrypickGenerated();
|
||||
// ... остальной код
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
import 'package:cherrypick_annotations/cherrypick_annotations.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
import '../data/network/json_placeholder_api.dart';
|
||||
import '../data/post_repository_impl.dart';
|
||||
import '../domain/repository/post_repository.dart';
|
||||
|
||||
class AppModule extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
bind<Dio>().toProvide(() => Dio()).singleton();
|
||||
part 'app_module.cherrypick.g.dart';
|
||||
|
||||
bind<JsonPlaceholderApi>()
|
||||
.toProvide(() => JsonPlaceholderApi(currentScope.resolve<Dio>()))
|
||||
.singleton();
|
||||
@module()
|
||||
abstract class AppModule extends Module {
|
||||
@singleton()
|
||||
Dio dio() => Dio();
|
||||
|
||||
bind<PostRepository>()
|
||||
.toProvide(() =>
|
||||
PostRepositoryImpl(currentScope.resolve<JsonPlaceholderApi>()))
|
||||
.singleton();
|
||||
}
|
||||
@singleton()
|
||||
JsonPlaceholderApi api(Dio dio) => JsonPlaceholderApi(dio);
|
||||
|
||||
@singleton()
|
||||
PostRepository repo(JsonPlaceholderApi api) => PostRepositoryImpl(api);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'router/app_router.dart';
|
||||
|
||||
void main() {
|
||||
final scope = CherryPick.openRootScope();
|
||||
scope.installModules([AppModule()]);
|
||||
scope.installModules([$AppModule()]);
|
||||
|
||||
runApp(MyApp(scope: scope));
|
||||
}
|
||||
|
||||
@@ -156,7 +156,21 @@ packages:
|
||||
path: "../../cherrypick"
|
||||
relative: true
|
||||
source: path
|
||||
version: "2.1.0"
|
||||
version: "2.1.0-dev.1"
|
||||
cherrypick_annotations:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../../cherrypick_annotations"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.0.0"
|
||||
cherrypick_generator:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
path: "../../cherrypick_generator"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.0.0"
|
||||
clock:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -12,7 +12,8 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
cherrypick: ^2.1.0
|
||||
cherrypick: any
|
||||
cherrypick_annotations: any
|
||||
|
||||
dio: ^5.4.0
|
||||
retrofit: ^4.0.3
|
||||
@@ -29,7 +30,9 @@ dev_dependencies:
|
||||
|
||||
flutter_lints: ^4.0.0
|
||||
|
||||
build_runner: ^2.4.6
|
||||
cherrypick_generator: any
|
||||
build_runner: any
|
||||
|
||||
retrofit_generator: ^8.0.4
|
||||
freezed: ^2.3.2
|
||||
json_serializable: any
|
||||
|
||||
@@ -17,7 +17,7 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
scope = CherryPick.openRootScope();
|
||||
scope.installModules([AppModule()]);
|
||||
scope.installModules([$AppModule()]);
|
||||
});
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
expect(1, 1);
|
||||
|
||||
Reference in New Issue
Block a user