Swift Dependency Injection With Functions

Written by twittemb | Published 2020/08/20
Tech Story Tags: swift | dependency-injection | functional-programming | higher-order-functions | code-quality | testing | software-development | software-engineering

TLDR Dependency injection is a technique at the crossroads of well known software engineering best practices: abstraction and decoupling, single responsibility, dependency inversion. It provides flexible and testable implementations of higher order free functions. This article assumes that the merits of dependency injection are accepted. We will see how dependency injection and higher order functions fit very well together. The UsersRepository is injected with an ApiService protocol whose purpose is to fetch users from the Rest endpoints. The repository doesn’t care about where they come from, it is an implementation detail. The publisher should only be built if and when needed.via the TL;DR App

no story

Written by twittemb | Mobile Architect in Montreal
Published by HackerNoon on 2020/08/20