Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought

Welcome, Guest. Please login or register.
December 18, 2017, 04:03:14 AM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1]
Author Topic: Shared Database Connections  (Read 3882 times)
Posts: 4

View Profile Email
« on: October 13, 2009, 08:56:34 PM »

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?


Global Moderator
Hero Member
Posts: 2871

View Profile WWW
« Reply #1 on: October 15, 2009, 09:55:09 AM »

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.

Pages: [1]
Jump to: