dependency-injection_skill

This skill provides expert dependency injection guidance for iOS/tvOS, optimizing testability and flexibility through patterns, protocols, and environment
  • Shell

6

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill kaakati/rails-enterprise-dev --skill dependency-injection

  • SKILL.md11.0 KB

Overview

This skill provides pragmatic, opinionated guidance for dependency injection decisions in iOS and tvOS projects. It helps you choose when DI adds value, which injection pattern to use, how to design protocols for testability, and SwiftUI-specific injection strategies. The focus is practical trade-offs so teams avoid over-engineering and brittle test setups.

How this skill works

I apply a decision framework that starts with whether a dependency needs independent testing and how many consumers it has. Recommendations cover constructor, default-parameter, property, factory patterns, lightweight manual containers, and when to adopt a DI library. SwiftUI injection via Environment, EnvironmentObject, and app-level wiring is included with concrete examples and anti-pattern warnings.

When to use it

  • Designing a service layer that will be mocked in unit tests
  • Deciding if a dependency should be protocol-abstracted or used as a concrete type
  • Wiring app-wide services across many view models and views
  • Setting up test infrastructure and mocks with verification
  • Evaluating whether a DI container is justified for team size and complexity

Best practices

  • Prefer constructor injection for guaranteed valid state and explicit dependencies
  • Use protocols only when a dependency will be mocked or when wrapping external modules
  • Avoid property injection unless a framework forces it or the dependency genuinely changes at runtime
  • Keep protocols minimal—expose only the behavior the consumer needs
  • Avoid service locator patterns and classes with >5 constructor dependencies; split responsibilities

Example use cases

  • Small app: default parameter injection for convenience and simple manual factories for tests
  • Medium team: a single manual container with lazy singletons and factory methods to centralize wiring
  • Large codebase: evaluate Swinject or similar only if manual wiring becomes error-prone
  • SwiftUI app: inject services at the App level with a custom EnvironmentKey and override in tests
  • Testing: create stubbed mocks that track calls and verify behavior on the system under test

FAQ

Create a protocol if you will mock it in tests, need to decouple from an external module, or expect the interface to change; skip protocols for pure value helpers.

Is a DI container always necessary for large apps?

Not always. Start with a simple manual container; adopt a DI library only when manual wiring causes maintenance pain across many teams or modules.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational