Profile picture
, 13 tweets, 4 min read Read on Twitter
Here's a little thread on DI, and how I think about @insertkoin_io
First, let's start by recognizing the really good documentation and branding work here 👏. I really think that on top of good code and APIs, OSS libraries need nice and easy to read documentation, and a dose of fun.
I don't quite agree with @JakeWharton that Koin is the same as manual DI. It's core is essentially a Map<Key, Factory>, which is also what most DI libraries are (Dagger 2 being the weird exception)

3 years ago I gave a talk showing how to rebuild DI libraries from scratch, to highlight the core principles:… 🗣
Step 1 is to create a Map<Key, Factory> 🗺🔑🏭 then manually adding factories, and providing the factory callbacks with access to the map so that they can obtain their deps by key. This "service locator" happens inside factories rather then within the constructor.
As an example, check out , a PHP lib that fits in a tweet: . 10 years ago I wrote a similar java DI lib, Yasdic: . Koin is very similar in concept, with less boilerplate thanks to Kotlin.
Most DI libs reduce boilerplate further by removing the need to manually declare all the factories. Guice used reflection to add factories. Spring used XML and reflection. Dagger 1 generated the factories and linked them with reflection. Toothpick.. I'm not sure 🤷‍♂️
Dagger 2 generates factories and then turns the map into generated code, where keys are component fields. In a way, it's the closest thing to manual DI. It writes for you the boilerplate you'd write if you used manual DI.
Use what works for you! All these libs work well in some context. I like relying on generated code because in a large codebase that leads to less touch points when making changes.✌️
@JakeWharton Implementation details are important to reason about software because all abstractions leak. I give a shit how things are built. You sure generally do, as well 😘

Koin with reflection still requires to declare factories, not much better

I'm simply trying to demystify DI libs and show the differences so that people can compare and reason about. I wouldn't use Koin nor recommend it, and would take even Guice or Toothpick over. If people like factories and service locators then 🤷‍♂️

Let's start the DI Alliance organization and start DI lib certifications! 💰

Sorry @JakeWharton I shouldn't have brought you in this conversation, wasn't intentionally trying to start a fight.
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Py ⚔
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!