金色时刻 · 15:48
让好资源,触手可及
AGENT SKILL

dependency-injection

dependency-injection 是面向测试与安全的 Agent Skill,来自 HoangNguyen0403/agent-skills-standard。查看技能说明、操作步骤与使用约定,并通过原项目了解详细用法。

Standards for automated service locator setup using injectable and get_it.

SKILL.md

下载 MD ↓
nameFlutter Dependency Injection (Injectable)
descriptionStandards for automated service locator setup using injectable and get_it.
metadata{"labels": ["dependency-injection", "injectable", "get_it"], "triggers": {"files": ["**/injection.dart", "**/locator.dart"], "keywords": ["GetIt", "injectable", "singleton", "module", "lazySingleton", "factory"]}}

Dependency Injection

Priority: P1 (HIGH)

Automated class dependency management using get_it and injectable.

Structure

core/injection/
├── injection.dart # Initialization & setup
└── modules/ # Third-party dependency modules (Dio, Storage)

Implementation Guidelines

  • Automated Registration: Use @injectable annotations; avoid manual registry calls.
  • @LazySingleton: Default for repositories, services, and data sources (init on demand).
  • @injectable (Factory): Default for BLoCs to ensure state resets on every request.
  • Abstract Injection: Always register implementations as abstract interfaces (as: IService).
  • Modules: Use @module for registering third-party instances (e.g., Dio, SharedPreferences).
  • Constructor Injection: Use mandatory constructor parameters; injectable resolves them.
  • Test Mocks: Swap implementations in setUp using getIt.registerLazySingleton for testing.

Reference & Examples

For module configuration and initialization templates: See references/REFERENCE.md.

Related Topics

layer-based-clean-architecture | testing

来源:HoangNguyen0403/agent-skills-standard · MIT 许可 · 许可原文 · MD 为来源页保存的历史版本