smf_get_it 0.4.2
smf_get_it: ^0.4.2 copied to clipboard
The SMF module of dependency injection with get_it for the Flutter app that SMF generates. It registers the services that the modules of the app declare.
Generate a Flutter app with get_it #
get_it is the module of the SMF CLI that provides dependency injection with get_it. Choose it with -m, here together with event_bus, whose service it registers:
dart pub global activate smf_flutter_cli
smf create my_app -m get_it,event_bus --no-input
The modules of the app declare their services, and this module registers them in lib/core/di/dependencies.dart:
Future<void> registerDependencies() async {
final getIt = GetIt.instance;
getIt.registerLazySingleton<di0.CommunicationService>(
() => di0.createCommunicationService(),
);
}
bootstrap() awaits registerDependencies() before the first frame, and resetDependencies() resets get_it for a test that registers the services again. Only the composition file of a feature takes services, with resolve<T>() of the ServiceLocator of the dependency injection role, which does not name get_it. The rest of the app gets its services as parameters.
Without -m, smf create asks which module provides dependency injection. When a module you chose needs it and get_it is the only module that provides it, smf create adds get_it by itself.
The documentation has more on the get_it module and on services and state.