jeudi 5 février 2015

How to create singletone pattern of the following class

I have class to create object context. To manage object creation I want to use single tone pattern. How to create following class object creation pattern as singletone in C#.



public abstract class EFContextBase<TContext> : IDisposable where TContext : ObjectContext, new()
{
private TContext _dataContext;
protected virtual TContext DataContext
{
get
{
if ((object)this._dataContext == null)
this._dataContext = Activator.CreateInstance<TContext>();
return this._dataContext;
}
}

public EFContextBase()
{
this.DataContext.ContextOptions.LazyLoadingEnabled = true;
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize((object)this);
}
private void Dispose(bool disposing)
{
if (!disposing || (object)this._dataContext == null)
return;
this._dataContext.Dispose();
this._dataContext = default(TContext);
}
}

Aucun commentaire:

Enregistrer un commentaire