Singleton tạo một instance cho toàn bộ app: getIt.registerSingleton<Repository>(Repository()).
- Dùng cho tài nguyên chia sẻ (database, API client, repository).
- Factory tạo instance mới mỗi lần:
getIt.registerFactory<UserBloc>(() => UserBloc(repo)). - Dùng cho BLoC (mỗi màn hình cần state độc lập).
- Dùng sai gây state leak (chia sẻ state có thể thay đổi) hoặc lãng phí bộ nhớ.
Singleton creates one instance for the entire app — use for shared resources like databases and API clients.
- Factory creates a new instance each time — use for BLoCs where each screen needs independent state.
- Misuse causes state leaks or unnecessary memory consumption.