In this video, Mark DiFranco introduces the dependency injection container. He explains how the DI container makes implementing dependency injection much easier. A quick diagram at the end of the video explains how the DI container works under the hood.
- [Instructor] Since our classes now have…complicated initializers, we're going to need a way…to make them easier to instantiate.…A Dependency Injection Container,…or a DI container for short, can help us do this.…The container will keep a map of each class type…to an instance of that class.…We can then instantiate any class…by simply providing the type to the container.…The container then automatically provides…dependencies for the class.…Let's take a look at a quick example…to get an idea of how this works.…So on the right we have a diagram…representing our DI container.…
We would ask it for a URLSession class,…and then it would instantiate a URLSession…and provide the class back.…We can then register several of these classes.…And then when we ask for a PhotoDownloader class,…it can then create a URLSession and a URLCache class,…and then create the PhotoDownloader class for us…and return the class to us.…This allows us to create the PhotoDownloader class,…rather than having to instantiate…all of the dependencies ourselves.…
- Why write unit tests?
- What is dependency injection?
- Using protocols to help with tests
- Handling external dependencies
- Anatomy of a test case
- Writing tests
- Analyzing code coverage
- Visualizing test results
- Writing and extending UI tests
Skill Level Intermediate
1. Dependency Injection
2. Using Protocols
3. Writing Tests
4. UI Tests
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.