unyo-dependency-injection

Organize GetIt dependency injection for Unyo Flutter apps with two-phase initialization.

651|26|Updated Mar 24, 2024
One-click install
npx skills add https://github.com/K3vinb5/Unyo --skill unyo-dependency-injection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unyo-dependency-injection
Source: https://github.com/K3vinb5/Unyo/tree/main/.agents/skills/unyo-dependency-injection
Command: npx skills add https://github.com/K3vinb5/Unyo --skill unyo-dependency-injection

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Centralizes and standardizes dependency injection for the Unyo Flutter app using GetIt, enabling consistent registration, resolution, and debugging across services, repositories, cubits, and notifiers.

Core Features & Use Cases

  • Clear two-phase initialization guidance (setupLocator before runApp and setupLocatorAfterHiveInit after Hive initializes) to accommodate async platform dependencies and Hive storage.
  • Detailed registration patterns: singletons, lazy singletons, factories, and async singletons with support for named instances and safe resolution.
  • Robust wiring and guardrails against common pitfalls like missing registrations, circular dependencies, and improper scoping across components.
  • Real-world use: wire a new Studio feature by registering its notifier, repository, and cubit in the correct phase.

Quick Start

Configure the locator to register dependencies before running the app.

Frequently Asked Questions about unyo-dependency-injection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I organize dependency injection in a Flutter app using GetIt?

To organize dependency injection with GetIt, centralize all registrations for services, repositories, cubits, and notifiers within a dedicated locator. This standardizes resolution and debugging while applying two-phase initialization to safely handle both synchronous and asynchronous dependencies.

What is two-phase initialization in GetIt for Flutter apps?

Two-phase initialization in GetIt splits locator setup into setupLocator before runApp and setupLocatorAfterHiveInit after Hive initializes. This accommodates async platform dependencies and Hive storage, ensuring platform and storage-dependent components are registered safely.

When should I use singletons, lazy singletons, or factories in GetIt?

Use GetIt singletons for eager global instances, lazy singletons for resource-heavy objects created on first access, and factories for fresh instances on every resolution. Applying these registration types with named instances and lifecycle rules ensures safe and predictable wiring.

How do I wire a new cubit and notifier into a Flutter GetIt locator?

Wiring a new cubit and notifier into a GetIt locator requires registering both components in the correct initialization phase. You must specify the appropriate registration type, apply naming conventions, and resolve any repository dependencies safely to prevent missing registrations.

Does GetIt support async dependency registration for Flutter applications?

GetIt supports async singletons for Flutter applications requiring asynchronous dependency registration. This is utilized during the second initialization phase after Hive initializes, allowing the locator to safely resolve components that depend on async platform services or local storage.

Why does my GetIt dependency injection fail with missing registrations or circular dependencies?

GetIt dependency injection fails with missing registrations or circular dependencies when components are improperly scoped or resolved before initialization. Guardrails against these common pitfalls require strict adherence to two-phase initialization, correct registration types, and established naming conventions.