원클릭으로
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 직업 분류 기준
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.
| 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