Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manually inject local micro package modules #483

Open
Jaew00Shin opened this issue Oct 13, 2024 · 0 comments
Open

manually inject local micro package modules #483

Jaew00Shin opened this issue Oct 13, 2024 · 0 comments

Comments

@Jaew00Shin
Copy link

import 'package:app_factory_core/app_factory_core.dart';
import 'package:app_factory_dev/src/di/configure_dependencies.config.dart';
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';

final getIt = GetIt.instance;

@InjectableInit(
  asExtension: false,
  generateForDir: ['lib/src/di'],
  initializerName: r'$initModuleGetIt',
  includeMicroPackages: false,
  externalPackageModulesAfter: [
    ExternalModule(AppFactoryCorePackageModule),
  ],
)
Future<void> configureDependencies() async {
  $initModuleGetIt(getIt);
}

The above one is working well.
AppFactoryCorePackageModule is external package from the other package.

dependencies:
  app_factory_core:
    path: ../app_factory_core

AppFactoryCorePakcageModule is defined and is generated in app_factory_core.

But,

import 'package:app_factory_core/app_factory_core.dart';
import 'package:app_factory_dev/src/di/configure_dependencies.config.dart';
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';

import 'initialize_app_dependencies.module.dart';

final getIt = GetIt.instance;

@InjectableInit(
  asExtension: false,
  generateForDir: ['lib/src/di'],
  initializerName: r'$initModuleGetIt',
  includeMicroPackages: false,
  externalPackageModulesAfter: [
    ExternalModule(AppFactoryCorePackageModule),
    ExternalModule(AppFactoryDevPackageModule),
  ],
)
Future<void> configureDependencies() async {
  $initModuleGetIt(getIt);
}

If I add local micro package AppFactoryDevPackageModule, FormatException occurs.

[INFO] Running build...
[app_factory_dev]: [SEVERE] injectable_generator:injectable_config_builder on lib/src/di/configure_dependencies.dart:
[app_factory_dev]: 
[app_factory_dev]: FormatException: Not an instance of Type.
[app_factory_dev]: [INFO] Running build completed, took 287ms
[app_factory_dev]: 
[app_factory_dev]: [INFO] Caching finalized dependency graph...
[app_factory_dev]: [INFO] Caching finalized dependency graph completed, took 51ms
[app_factory_dev]: 
[app_factory_dev]: [SEVERE] Failed after 341ms

The document in pub.dev said that "it's also possible to include micro local or external modules manually by passing them to the externalPackageModules property inside of @injectableInit so they're initialized with the rest of the local dependencies."
But it doesn't work to manually pass local modules.

How can I add local modules to externalPackagesModule?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant