Hi,
I am looking for the Clojure equivalent of:
class Whatever {
@Transactional
void doSomething(IDoSomething one, IDoSomethingElse two) {
one.doSomething()
two.doSomething()
}
}
where both one and two are dependency injected with a proxy which resolves
to a thread local database connection. In addition, one might itself have a
collaborator which itself has a collaborator which needs a datasource.
So far I have two protocols:
(defprotocol IDoSomething
(do-something [this ...])
(defprotocol IDoSomethingElse
(do-something [this ...])
Each protocol may have a number of implementations, one of which is a JDBC
implementation:
(defrecord JdbcIDoSomething [db]
(do-something [this ...] ...))
The problem is that the calling code only gets provided an IDoSomething and
an IDoSomethingElse and it wants to do something like:
(let [one (->JdbcDoSomething db) two (->JdbcDoSomethingElse db)]
(with-transaction [tx db]
(do-something one)
(do-something-else two)))
The problem here is that the implementations of do-something and
do-something-else won't have access to the local bound 'tx', they will have
their own 'db'.
I realise the general argument is to be explicit and pass a db as the first
argument to the protocol but this isn't appropriate in this case as there
are validly multiple implementations. I could abstract a 'unit-of-work' and
pass that as the first argument to the protocols but that seems a bit
painful.
Also, these protocols may be used quite far away from where the database
code lives and passing a parameter all the way through the call stack is
painful.
I am using Stuart Sierra's components if that makes any difference.
I can't be the first person to run into this but google is surprisingly
unhelpful which makes me think I have missed something fundamental, and
that I have something upside down.
What do you all do?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.