I'm wondering if it makes sense to try and open just one DataAccessAdapter per thread. That is, I create my own data manager classes that each are executed by using the standard singleton pattern. That is, I execute these static classes like:
CodeTestManager.I.Get(...);
They are all [ThreadStatic] so I'm confident I won't have any threading issues since a new instance is created on each thread automatically for me.
So my question is, if I create one adapter (rather than using the "using" syntax, is that a recommended way to go? Or, is creating an adapter on every page invocation of a manager class OK. My code is below.
public abstract class ManagerBase<TManager, TResult, TEntity> where TEntity : class, new()
where TManager : class, new()
where TResult : ResultBase
{
protected static LinqMetaData _meta;
private static readonly object SingletonLock = new object();
[ThreadStatic]
private static TManager _instance;
public static TManager I
{
get
{
if (_instance == null)
{
lock (SingletonLock)
{
if (_instance == null)
{
_instance = new TManager();
//using (var adapter = new DataAccessAdapter())
{
var adapter = new DataAccessAdapter();
adapter.ConnectionString = "Data Source=.;Initial Catalog=3plogic ;Persist Security Info=True;User ID=3plogic ;Password=xx";
_meta = new LinqMetaData(adapter);
}
}
}
}
return _instance;
}
}
I know .dispose is never called, but the idea is this adapter lives for the life of the applicaiton.