Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Koin vs Dagger (Service Locator vs D.I.)

Koin vs Dagger (Service Locator vs D.I.)

With Koin 2.0 it’s time for us to evaluate this age old debate. What exactly do we mean by service locator vs dependency injection? Does it matter in a modern age? I will discuss this topic along with how both libraries are implemented with an emphasis on their differences and how that affects us.

BrianPlummer

August 26, 2019
Tweet

More Decks by BrianPlummer

Other Decks in Programming

Transcript

  1. –Michael Mattsson 1996 “This inversion of control is sometimes named

    the Hollywood principle, “Do not call us, we call You””
  2. Martin Fowler • Popularized the term Dependency Injection • A

    signing member of the Manifesto for Agile Software Development • Inversion of Control Containers and the Dependency Injection pattern • Strangler Fig Pattern
  3. Why is no injection bad? • No Inversion of Control

    • Can’t mock out our data source
  4. The service locator pattern is used to encapsulate the processes

    involved in obtaining a service with a strong abstraction layer
  5. Conclusions on DI vs SL • Both provide separation •

    Difference is how dependencies are provided • Not mutually exclusive
  6. Not mutually exclusive? • Dependencies created with injection -> served

    up via service locator • Can create dependencies with constructor injection
  7. Thoughts - Costs • What are the costs? • Increased

    complexity? • Increased build time?
  8. Thoughts - You! • What is your situation? • Greenfield

    vs Existing • Onboarding of new developers
  9. What does it give us? • Abstracts how we construct

    our dependencies • Improves testability • Scoping
  10. –Martin Fowler “The choice between Service Locator and Dependency Injection

    is less important than the principle of separating service configuration from the use of services within an application.”