I have a WinForms application which uses Entity Framework 5.0.
I want to keep the context short-lived by instantiating and disposing it on a user-story basis. For example - user clicks save, then instantiate the context, save, and dispose.
In addition to that, I have a service layer, and I inject the same context to the services.
The issue is that I am ending up with lengthy code in each of my user-story handlers. For example:
void OnSaveButtonClick(object sender, EventArgs e)
{
using (var context = new MyEntities())
{
var transactionService = new TransactionService(context);
transactionService.SaveTransaction(...);
}
}
So I am just wondering if there is any pattern (or DBContext's event) that I could use to keep the code "readable" for my client. Much appreciated.