Created
May 10, 2013 10:47
-
-
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.
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 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