بنقرة واحدة
register-dependency
Register and access dependencies in Modugo modules using GetIt via the binds() method
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Register and access dependencies in Modugo modules using GetIt via the binds() method
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
| name | register-dependency |
| description | Register and access dependencies in Modugo modules using GetIt via the binds() method |
Dependencies are registered in the binds() method of a module using i (the GetIt instance).
@override
void binds() {
// New instance every time get<T>() is called
i.registerFactory<MyRepository>(() => MyRepositoryImpl());
// Single instance for the entire app lifetime
i.registerSingleton<AuthService>(AuthService());
// Single instance, created on first use
i.registerLazySingleton<AnalyticsService>(() => AnalyticsService());
// Async singleton (e.g. needs await to initialize)
i.registerSingletonAsync<Database>(() async {
final db = Database();
await db.init();
return db;
});
}
Pass them via constructor — i.get<T>() resolves the dependency:
i.registerFactory<ProfileViewModel>(
() => ProfileViewModel(i.get<ProfileRepository>()),
);
Three equivalent ways:
// In any Dart code
final service = i.get<AuthService>();
final service = Modugo.i.get<AuthService>();
// Inside a widget (requires BuildContext)
final service = context.read<AuthService>();
To reuse binds from another module without re-registering:
final class ProfileModule extends Module {
@override
List<Type> imports() => [CoreModule]; // shares CoreModule's binds
@override
void binds() {
// CoreModule's binds are already available via i.get<T>()
i.registerFactory<ProfileViewModel>(() => ProfileViewModel(i.get()));
}
}
registerFactory for ViewModels/Controllers and registerLazySingleton for servicesregisterSingletonAsync for dependencies that require async initialization (e.g. databases, shared preferences)Modugo's DI is powered by GetIt. For advanced registration patterns (scopes, named instances, async ready-check), consult GetIt docs directly:
use context7 with /fluttercommunity/get_it for advanced DI patterns
Create and apply route guards in Modugo to protect routes with conditional logic
Create a new Modugo module with routes, binds, and imports
Create routes in Modugo using ChildRoute, ModuleRoute, ShellModuleRoute, StatefulShellModuleRoute, or AliasRoute
Contexto completo do projeto Modugo — lib Flutter de roteamento modular e injeção de dependência sobre GoRouter + GetIt. Carregue esta skill sempre que for explorar, implementar, especificar ou revisar qualquer coisa no repositório.