Skip to content

Instantly share code, notes, and snippets.

@jgauffin
Created September 11, 2013 13:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jgauffin/6523472 to your computer and use it in GitHub Desktop.
Save jgauffin/6523472 to your computer and use it in GitHub Desktop.
Examples on how to create unit of work in WinForms/WPF applications
// simple example, can of course be simplified using a ioc wrapper.
public void Button1_Clicked(object source, EventArgs empty)
{
using (var scope = Program.Autofac.BeginLifetimeScope())
{
var uow = scope.Resolve<IUnitOfWork>();
var repos = scope.Resolve<IUserRepository>();
var user = repos.GetUser(1);
user.LastName = txtLastName.Text;
repos.Save(user);
uow.Commit();
}
}
public void Button1_Clicked(object source, EventArgs empty)
{
using (var uow = UnitOfWorkFactory.Create())
{
var repos = new UserRepository(uow);
var user = repos.GetUser(1);
user.LastName = txtLastName.Text;
repos.Save(user);
uow.Commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment