Skip to content

Instantly share code, notes, and snippets.

@GregOnNet
Created May 10, 2013 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GregOnNet/5553681 to your computer and use it in GitHub Desktop.
Save GregOnNet/5553681 to your computer and use it in GitHub Desktop.
Refactored the using-Statement to a seperate method. Reduced code smell in DAO-methods.
public class EntityOperation : IEntityOperation
{
readonly ISession _session;
public EntityOperation(ISession session)
{
_session = session;
}
public void Save(object entity)
{
Commit(
() => _session.Save(entity));
}
public void Update(object entity)
{
Commit(
() => _session.Update(entity));
}
public void Delete(object entity)
{
Commit(
() => _session.Delete(entity));
}
private void Commit(Action action)
{
using (var t = _session.BeginTransaction())
{
action.Invoke();
t.Commit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment