Skip to content

Instantly share code, notes, and snippets.

@Spaider
Created February 22, 2013 09:04
Show Gist options
  • Save Spaider/5011922 to your computer and use it in GitHub Desktop.
Save Spaider/5011922 to your computer and use it in GitHub Desktop.
Shows how to work with DB instances in custom data accessors.
/// <summary>
/// Accessor for working with Stuff
/// </summary>
public static class SampleDataAccessor
{
/// <summary>
/// This overload opens DB connection and thus, manages DB state.
/// Wrapping creation in using clause ensures that it will be
/// properly disposed
/// </summary>
public static void SaveStuff(Stuff stuff)
{
using(var db = new AthlinksDB())
{
db.BeginTransaction();
SaveStuff(db, stuff);
db.CommitTransaction();
}
}
/// <summary>
/// This overload receive DB instances and thus does not try
/// to manage its state, just does actual work.
/// Possible exceptions will be passed upwards
/// </summary>
public static void SaveStuff(AthlinksDB db, Stuff stuff)
{
// Save stuff actually
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment