Title: Shared Database Connections Post by: andremolnar on October 13, 2009, 08:56:34 Hello all.
This must be a common question and I did see some discussion about it as it relates to an AIR app, but I got a bit lost: Basically what I would like to do is share a database connection between proxies. First thought: Just make the connection in each proxy. Conclusion: That's just silly. Second thought: Create a multiton that returns a database connection (actually a PDO object). Then add DbConnection::getInstance('instancename') to the proxy constructor. That way the connections are shared and I have the flexibility to have more than one database connection type and I can share as many of them as I like/need between any number of proxies. Conclusion: I've built in a dependency. Third thought: Use the same multiton (for the same reasons), but inject the dependency. Conclusion: Ummm, I'm not sure, because I would have to inject the database connection object from the point where I create the proxy (i.e. a command). Is that the place for me to be getting that connection instance? I really don't see where else I could do it. Or am I barking up the wrong tree altogether? Thoughts? andre Title: Re: Shared Database Connections Post by: puremvc on October 15, 2009, 09:55:09 There's no real problem with having dependencies between Proxies.
You could always have a DBConnectionProxy, and pass it to the other Proxies on their constructors when they're created, or have those proxies retrieve it as needed. -=Cliff> |