Created
September 11, 2013 13:18
-
-
Save jgauffin/6523472 to your computer and use it in GitHub Desktop.
Examples on how to create unit of work in WinForms/WPF applications
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
// 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(); | |
} | |
} |
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 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