Managing Stateful Components

Most applications will rely on stateful external resources such as database connections and queues. These resources often have a life cycle associated with them. Typically, we would like to start such resources when the application initializes and stop them when it shuts down.

One popular approach for managing stateful resources in object-oriented languages is to use a dependency injection framework. This approach can also be used in Clojure using the Component library. It’s a solid approach. One major downside is that it requires us to structure our app around it.[38]

Another problem with Component is that stateful resources are described using protocols. This doesn’t play well with the REPL workflow, because ...

Get Web Development with Clojure, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.