Dependency Injection Made Modular

Episode #92 • Feb 24, 2020 • Subscriber-Only

Now that we’ve baked the “environment” of dependencies directly into the Composable Architecture, we’re ready to refactor our app’s frameworks and tests to work with them in a modular and more lightweight way.

Dependency Injection Made Modular
Introduction
00:05
Using the architecture’s environment
00:54
Tuplizing the environment
10:46
Testing with the environment
19:50
Next time: what’s the point?
31:55

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Introduction

The ComposableArchitecture is now building again, but we have greatly simplified the API of the Store type.

Now let’s get the rest of the app building.

Luckily the app is fully modularized, and so we can start with our simplest modules that have the fewest dependencies, and work our way back to the main app target. Also lucky for us is that we are already using the environment technique in our code, and that will make converting to this new style very easy.

This episode is for subscribers only.

Subscribe to Point-Free

Access this episode, plus all past and future episodes when you become a subscriber.

See plans and pricing

Already a subscriber? Log in

Exercises

  1. Introduce an “offline counter view,” which reuses the CounterView with an offline version of the nthPrimeModal. Show that both views can exist in harmony in the environmental architecture.

    Solution

    Stay tuned for a solution in next week’s episode!

  2. Update the favorite primes module to hit Wolfram Alpha and show an alert, just as the counter module does when the “What is the nth prime?” button is tapped.

    Ensure that the root reducer shares the same dependency with each module.

    Solution

    Stay tuned for a solution in next week’s episode!

References

Dependency Injection Made Easy

Brandon Williams & Stephen Celis • Monday May 21, 2018

This is the episode that first introduced our Current environment approach to dependency injection.

Today we’re going to control the world! Well, dependencies to the outside world, at least. We’ll define the “dependency injection” problem and show a lightweight solution that can be implemented in your code base with little work and no third party library.

Dependency Injection Made Comfortable

Brandon Williams & Stephen Celis • Monday Jun 4, 2018

Let’s have some fun with the “environment” form of dependency injection we previously explored. We’re going to extract out a few more dependencies, strengthen our mocks, and use our Overture library to make manipulating the environment friendlier.

How to Control the World

Stephen Celis • Monday Sep 24, 2018

Stephen gave a talk on our Environment-based approach to dependency injection at NSSpain 2018. He starts with the basics and slowly builds up to controlling more and more complex dependencies.

Effectful State Management: Synchronous Effects

Brandon Williams & Stephen Celis • Monday Oct 14, 2019

This is the start of our series of episodes on “effectful” state management, in which we explore how to capture the idea of side effects directly in our composable architecture.

Side effects are one of the biggest sources of complexity in any application. It’s time to figure out how to model effects in our architecture. We begin by adding a few new side effects, and then showing how synchronous effects can be handled by altering the signature of our reducers.

Testable State Management: Reducers

Brandon Williams & Stephen Celis • Monday Nov 25, 2019

This is the start of our series of episodes on “testable” state management, in which we explore just how testable the Composable Architecture is, effects and all!

It’s time to see how our architecture handles the fifth and final problem we identified as being important to solve when building a moderately complex application: testing! Let’s get our feet wet and write some tests for all of the reducers powering our application.