Skip to content

Instantly share code, notes, and snippets.

@cammerman
Created August 9, 2011 03:57
Show Gist options
  • Save cammerman/1133377 to your computer and use it in GitHub Desktop.
Save cammerman/1133377 to your computer and use it in GitHub Desktop.
Lifetime objects
public class DataContext : IDataContext
{
public DataContext(ISessionProvider sessionProvider)
{
this.SessionProvider = sessionProvider.ThrowIfNullArgument("sessionProvider");
}
private ISessionProvider SessionProvider { get; set;}
protected ISessionFacade Session
{
get
{
return this.SessionProvider.Session;
}
}
public virtual IQueryable<TModel> CreateQuery<TModel>()
{
// ...
}
public virtual TModel Fetch<TModel>(object id)
{
// ...
}
public virtual void TrackChanges<TModel>(TModel model)
{
// ...
}
public virtual void Delete<TModel>(TModel model)
{
// ...
}
}
public class PointReadingRepository : IPointReadingRepository
{
public PointReadingRepository(IDataContext context)
{
this.DataContext = context.ThrowIfNullArgument("context");
}
protected IDataContext DataContext { get; private set; }
public void Add(PointReading reading)
{
this.DataContext.TrackChanges(reading);
}
}
public class SessionProvider : ISessionProvider
{
public SessionProvider(IUnitOfWork unitOfWork)
{
// ...
}
private ISessionFacade _Session;
public ISessionFacade Session
{
get
{
return _Session;
}
}
}
public class UnitOfWork : IUnitOfWork
{
public UnitOfWork(ISessionManager sessionManager)
{
this.SessionManager = sessionManager.ThrowIfNullArgument("sessionManager");
}
public ISessionManager SessionManager { get; private set; }
public virtual bool HasStarted { get; private set; }
public virtual bool HasFinished { get; private set; }
public virtual bool WasCancelled { get; private set; }
public virtual void Start()
{
// ...
}
public virtual void Finish()
{
// ...
}
public virtual void CancelChanges()
{
// ...
}
public virtual void SubmitChanges()
{
// ...
}
public virtual void Dispose()
{
if (!this.HasFinished)
{
this.Finish();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment