3 ms·
In Clojure dependency injection is rare and typically explicit in some way or another. But the problem you describe does not happen as far as I understood it.
by dgb23 4y ago
In Clojure dependency injection is rare and typically explicit in some way or another. But the problem you describe does not happen as far as I understood it.
Dependency injection in that sense is only used in the "impure" parts, at the edge of your program, to build up application state.
A popular approach is using something like integrant, which describes dependencies as a plain data structure, which gets resolved as a dependency graph and calls into multimethods (polymorphic functions) that you provide to start/stop individual services or what have you.
Another popular approach is to use something like mount, which is basically just a macro which you use to describe how a service is started or stopped. All the dependency stuff is simply resolved via Clojure namespaces.
Both of these (and others) are done in a way so you can start/stop your whole app or parts of it, or just individual services in a REPL. Most of your code doesn't interact with these services, but gets called from them (functional core), so you typically don't need mocks or other such things in testing as your domain logic doesn't know anything about application state.