PDA

View Full Version : Question on SqlConnections, DAOs and Spring


eboix
05-09-2006, 05:28 PM
Hi all,

I'm developing a .Net app, and since I extensively use Spring.Java I started using Spring.Net.

Spring.Java has the JdbcTemplate support class which takes care of opening/closing connections and to coordinate the transactions (kind of, at least it helps in this process).

Spring.Net does not still have this, so I have to manage all this myself.

Now, how do I manage the SqlConnections ? I'm injecting my DAOs in my Business objects which in turn are injected in my ASPX files (all singleton).

What does make more sense ?
Do I create a "ConnectionFactory" bean, which creates the connections and hand them to the DAOs (on each method call) ?
Do I make the DAOs create their own connections (on each method) ?
In any case, this will led to trouble, since for example SQLServer ties a transaction to a connection, so using this method, I won't be able to create transactions reliably.

Do I create a "DaoFactory" which creates singleton DAO objects ? This way, I'll be able to use the same connection all the lifetime of the DAO, but I find this approach somewhat overkill...

Any suggestions ?

Regards,
Esteve

Mark Pollack
05-10-2006, 03:09 PM
Hi Esteve,

There is an initial version of AdoTemplate and the corresponding transaction infrastructure that you can use in CVS. This is scheduled for inclusion 1.1. PR3 and I've picked up development in this area as I prepare for a talk on this topic at SpringOne. You can get the latest code/assemblies from the nightly build.

Under the test directory is a Spring.Data.Integration.Tests project that shows some example usage. As you are familiar with Spring.Java you should feel right at home. The connection is provided though the use of a IDbProvider abstraction, along the lines of DataSource in Java and the provider approach in ADO.NET 2.0. The AdoPlatformTransactionManager binds a connection/tx pair to the thread so multiple DAO calls that use AdoTemplate will all use the same connection/tx pair.

Take a look around and ping back with any questions. Next week I'll be giving a talk on this topic as well, I'll post the slides once they are done.

Cheers,
Mark

eboix
05-10-2006, 03:24 PM
Great.

Thanks a lot Mark, and all the team, for all your work and help.

Regards,
Esteve