Better TransactionScope support

Topics: Data Access Application Block
Apr 11, 2007 at 2:15 AM
As I started coding the project last January I started to add TransactionScope support code outside the EntLib 2.0 code without knowing the 3.0 code. I found the code almost similar to the 3.0 EntLib except I think my code is better and it is used like this:
using (TransactionScope t = new TransactionScope())
{
using (DataAccess da = ServiceManager.GetDataAccess())
{
Obj obj = da.SelectAll<Obj>()0;
obj.Save(); //Get Ambient da and save it with it
t.Complete();
}
}

// DataAccess class code: ----------------------
public class DataAccess : IDisposable
{
public DataAccess()
{
if (AmbientDa ==null)
{
AmbientDa = this;
}
}

ThreadStatic
public static DataAccess AmbientDa;

ThreadStatic
//connstring, dbconnection
protected static Dictionary<string, DbConnection> DbConnections = new Dictionary<string, DbConnection>();
//EntLib Guys used this: private static Dictionary<Transaction,
// Dictionary<string, DbConnection>> transactionConnections = new
// Dictionary<Transaction, Dictionary<string, DbConnection>>();

public void Dispose()
{
if (AmbientDa == this)
{
//Dispose all connections in DbConnections
AmbientDa = null;
}
}
}