/SwiftDependencyInjectionCompared

A repository that uses 5 popular ways of doing Dependency Injection in SwiftUI applications

Primary LanguageSwift

Dependency Injection for Modern Swift Applications

Dependency Injection for Modern Swift Applications and Comparing five different approaches towards Dependency Injection

An AI generated hero image showing four syringes stuck into an apple, symbolifying the act of injecting dependencies on Apple platforms

This repo belongs to two articles I've written about dependency injection. I'm reviewing the following five principeles:

  • Compile-Time Safety - if it compiles, is it correct and crash-free?
  • Generational Safety - can we safely unlock dependencies later on?
  • Scalability - how hard is it to maintain or add features when the app grows?
  • Usability - how easy is it to new team members and to add or maintain features?
  • Testability - can we easily mock our dependencies for tests and previews?

This repo holds simple but complete examples that highlight the different aspects of DI for each different approach. The following five frameworks or techniques for DI have been selected to give a complete overview of all different types of solutions that exist:

Read the first article "Managing Dependencies in the Age of SwiftUI" here, and the second article "Comparing five different approaches towards Dependency Injection" here.