public static IDbConnection GetConnection(string connectionString, Func<string, DbConnection> createConnection)
{
// Prevent rouge threads from access the shared connection
Session.Tracker.AssertActivityStarted();
string key;
if (Transaction.TransactionInformation.DistributedIdentifier != Guid.Empty)
key = Transaction.TransactionInformation.DistributedIdentifier.ToString();
else
key = Transaction.TransactionInformation.LocalIdentifier;
key += "|" + connectionString;
AmnesiaDbConnection connection = null;
lock (connections)
{
if (!connections.TryGetValue(key, out connection))
{
connection = new AmnesiaDbConnection(Transaction, createConnection(connectionString));
connections[key] = connection;
}
}
return connection;
}