Dependency Injection for Modern Swift Applications and Comparing five different approaches towards Dependency Injection
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:
- Manual Tree - Pass all dependencies manually
- EnvironmentObject - Using SwiftUI's built in storage
- Factory - A simple statically declared container approach
- Needle - Uber's solution to boilerplate-heavy manual solutions
- Composable Architecture - How does TCA's solution compare?
Read the first article "Managing Dependencies in the Age of SwiftUI" here, and the second article "Comparing five different approaches towards Dependency Injection" here.