Swift Connection 2023 - Simon B. Støvring. - Achieving Loose Coupling with Pure Dependency Injection

Поделиться
HTML-код
  • Опубликовано: 24 окт 2023
  • Filmed at Swift Connection on September 2023. Find more talks of our conferences and meetups on 👉 async.techconnection.io/ 👈.
    Ensure loose coupling in your codebase by adopting Pure Dependency Injection and injecting the dependencies using the Composition Root pattern. Learn how to create a Composition Root and use the loose coupling to create feature apps that let you iterate on features in isolated environments.

    , Description,

    This is an inspirational talk that explores the Composition Root pattern (originally presented by Mark Seemann in the book “Dependency Injection in .NET”) in the context of a mobile app. Through the talk we will explore how the pattern can be used to achieve loose coupling and how the Composition Root and Pure Dependency Injection can be used as an alternative to the Service Locator pattern. As a result, we will notice that using Pure DI results in honest interfaces that clearly states the dependencies they need.

    While the concepts presented are mostly generic and applicable to all platforms, we will use an iOS app written in Swift as an example. Through the talk we will discover how Pure DI and the Composition Root makes it easy to mock parts of our codebase and create isolated apps that run a single feature, making it easy and fast to iterate on features without navigating through a large application.

    After the talk the audience will be well-equipped to consider Pure DI and the Composition Root as an alternative to the popular Service Locator pattern, which is effectively what the @Environment and @EnvironmentObject property wrappers in SwiftUI uses.

    , Notes,

    In early 2022 I started exploring different ways of doing dependency injection in my iOS apps and found that I dislike the popular approaches for doing dependency injection as they either open up for the possibility of runtime errors or are built on top of a third-party tool and I don’t believe it should require a dependency to manage your dependencies. Then I stumbled upon Mark Seemann’s description of Pure Dependency Injection and the Composition Root and immediately fell in love with this simple approach to managing dependencies.

    I have not given this talk before but I have submitted this proposal to a few conferences in 2023.

    I think the talk works great as a lightning talk that motivates people to think of dependency injection outside of @Environment, @EnvironmentObject, and popular third-party open-source packages for managing dependencies. This talk covers how we can do simple and secure dependency injection without needing to include a package.

    The talk can also work as a regular session if the organizers prefer. In that case I will dive deeper into how I use the Composition Root in my spare time projects and at my day job to build feature apps, tiny apps for testing features in isolation and typically with mocked data. I will also expand a bit on how the Composition Root pattern fits into unit testing.

Комментарии • 2