Last active
August 29, 2015 14:11
-
-
Save xfyre/f6a62b3f63ed01929054 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.myapp.tapestry.serviceregistry | |
(:import (org.apache.tapestry5.ioc ObjectLocator))) | |
(def ^:dynamic ^ObjectLocator *tapestry-registry-ref* (promise)) | |
(defn init-registry [^ObjectLocator registry] | |
"Must be called during service initialization to set up Tapestry registry object" | |
(deliver *tapestry-registry-ref* registry)) | |
(defmacro with-tapestry-services [service-bindings & body] | |
"Apply service bindings to body" | |
(let [service-binding-pairs# (partition-all 2 service-bindings) | |
service-binding-exprs# (map #(vector (first %1) `(.getService (deref *tapestry-registry-ref*) ~(second %1))) service-binding-pairs#) | |
service-binding-final# (vec (reduce concat service-binding-exprs#))] | |
`(let ~service-binding-final# ~@body))) | |
;; Usage | |
(with-tapestry-services [hibernate-session Session my-service MyService] | |
(defn do-something [arg & args] | |
;; use hibernate-session and my-service normally | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment