Injure - v1

I just released injure, a minimalistic dependency injector for clojure and clojurescript with zero runtime overhead.

The implementation is mostly a boring topological sort, and could really have been a 25-line job if there were a convenient helper to perform deep macroexpansion in clojurescript.

Feel free to share your thoughts about it.

3 Likes

It looks nice, I like that it is only focused on DI and nothing else.

That said, am I the only one who simply doesn’t need a DI framework for my Clojure programs? In Java, I couldn’t live without one, but haven’t needed it in Clojure yet.

Anyways, if I do one day, I’ll definitly check injure out as an option.

1 Like

I used to think that as well. From a smug lisper viewpoint, looking at all this reflection-based constructor/setter/interface injection nonsense that is now the norm in java ecosystem, it’s tempting to answer something like “DI is just argument passing” in an eyeroll, but I think that’s missing the point of DI. DI is about making dependencies explicit, if you can’t manipulate the topology of your system as data you don’t really do DI.

It’s easy to overlook DI because the problems it solves are generally easy to solve manually (topological sorting is easy enough for a human). However, hand-made solutions can be verbose. In my experience, the symptoms to observe for a potential DI cure are

  • many big let forms with slight variations over the same general shape (plumatic’s statistics example is typical : you have a global strategy to compute many things but you don’t always need every result)
  • a pipeline of functions taking a map and returning more items to merge in the map, such as the accumulated map is successively populated with more items depending on each other. This is a slight variation over the big let pattern where let bindings are replaced with map lookups.

I used to leverage the map function pipeline pattern to modularize my apps and switch easily between e.g dev and prod environments, until I figured out I was reinventing a wheel. plumatic’s graph was pretty much what I needed so I decided to have a deeper look at it, but it did not really sparked joy so I thanked it, then discarded it and finally made this thing instead.

2 Likes

Thanks for taking the time to explain dependency injection! I think posts like this make it a lot easier to understand the concepts for beginners.

I asked a question a while ago about architecture. It turned a little into dependency injection, since keeping control of resources and dependencies is really important. Feel free to comment there as well if you have anything to add!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.