Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Shared Database Connections  (Read 9017 times)
andremolnar
Newbie
*
Posts: 4


View Profile Email
« 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
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 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>
Logged
Pages: [1]
Print