In one of my previous posts I’ve shown how to setup and run a very simple TODO application. Apart from the application itself there was a bit of wiring to be done manually. This included, e.g. define and add integrant components to the config map, wrap application functions into integrant components, connect components together, etc. This is completely fine for small to medium sized projects but as your system grows, it could become a pain to do all of this yourself.
What if I’ll say you can reduce the hassle?
That’s how the Autowire module was born.
In short, Autowire is a Duct module which will scan all your project namespaces during the application startup and will create a Duct configuration for you on the fly.
All you need to do is to add this dependency to your Clojure project
[io.github.parencat/fx "0.1.2"]
Autowire relying heavily on Clojure metadata. In Clojure you can attach any additional information to symbols, maps, vectors, functions, etc. Autowire will look for specific key pairs in the metadata and use it to figure out which namespaces to load and how to create and configure integrant components.
Speaking of our TODO example. That’s how a Duct part would look like using Autowire (left side).
These code samples are identical in terms of functionality. As you can see, you need only a single line in the config map to enable autowiring instead of specifying all components.
{:duct.profile/base {...}
...
:fx.module/autowire {}}