Created
August 9, 2011 03:57
-
-
Save cammerman/1133377 to your computer and use it in GitHub Desktop.
Lifetime objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{ | |
// ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SessionProvider : ISessionProvider | |
{ | |
public SessionProvider(IUnitOfWork unitOfWork) | |
{ | |
// ... | |
} | |
private ISessionFacade _Session; | |
public ISessionFacade Session | |
{ | |
get | |
{ | |
return _Session; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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