Defining a SPI in Clojure

Posted by Joe Holloway on Stack Overflow See other posts from Stack Overflow or by Joe Holloway
Published on 2009-11-27T18:57:20Z Indexed on 2010/05/23 2:10 UTC
Read the original article Hit count: 427

Filed under:
|

I'm looking for an idiomatic way(s) to define an interface in Clojure that can be implemented by an external "service provider". My application would locate and instantiate the service provider module at runtime and delegate certain responsibilities to it.

Let's say, for example, that I'm implementing a RPC mechanism and I want to allow a custom middleware to be injected at configuration time. This middleware could pre-process the message, discard messages, wrap the message handler with logging, etc.

I know several ways to do this if I fall back to Java reflection, but feel that implementing it in Clojure would help my understanding.

(Note, I'm using SPI in a general sense here, not specifically referring to the way it's defined in the JAR file specification)

Thanks

© Stack Overflow or respective owner

Related posts about clojure

Related posts about service-provider