Milad-Akarie / injectable

Code Generator for get_it
MIT License
561 stars 142 forks source link

Including microPackages and external modules #416

Open herman-the-worm opened 11 months ago

herman-the-worm commented 11 months ago

Example of the project

-- lib/main.dart -- packages/authentication_repository/lib/authentication_repository.dart

lib/main.dart with AuthenticationBloc or any other class that depends on the Repository class (like AuthenticationRepository) which is exposed as an local package.

I have marked AuthenticationRepository class with @injectable

I have also included code snippet above AuthenticationRepository annotation

It looks like this

@microPackageInit void initAuthenticationRepository() {} // Needed for code generation

/// {@template authentication_repository} /// Repository which manages user authentication. /// {@endtemplate} @injectable class AuthenticationRepository {

  1. If I run build runner in the main.dart folder it does not automatically generate code for the module
  2. I have tried including the following in the getIt Injectable helper

import 'package:authentication_repository/authentication_repository.dart'; import 'package:checkmybuilding/shared/helper/get_it_service_locator.config.dart'; import 'package:get_it/get_it.dart'; import 'package:injectable/injectable.dart';

final getIt = GetIt.instance;

@InjectableInit( initializerName: r'$initGetIt', preferRelativeImports: true, includeMicroPackages: true, asExtension: false, generateForDir: [ 'lib', 'packages/authentication_repository/lib', ], externalPackageModulesBefore: [ ExternalModule(AuthenticationRepositoryPackageModule), ], )

But in this case I have to rebuild package in "authentication_repository" using build runner. It generates a file authentication_repository.module.dart. I have to include It in exports for the module and then import aforementioned file in the main.dart

Is there a way to automate this to build automatically for the dependent packages?

I am trying to understand if I am doing this correctly.

I would love to build a modular app and in the past (2 years ago) it was not possible with injectable and getIt but with this snippet of documentation I hope that it will be possible.

Thanks @Milad-Akarie

github-actions[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

dadagov125 commented 7 months ago

I have the same problem. Is there a solution?

davidcz95 commented 7 months ago

I was wondering exactly the same any tips or solution on that issue ?

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions