Last active
December 29, 2015 11:09
-
-
Save JakeGinnivan/7661360 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 static class nHibernateExtensions | |
| { | |
| public static T Transaction<T>(this ISession session, Action<ISession, T> action) | |
| { | |
| // 3. Enters here | |
| using (var tran = session.BeginTransaction()){ | |
| // 4. Calls into the lambda | |
| return action(tran); | |
| // 7. execution continues here | |
| } // 8. Transaction is commited/disposed | |
| // 9. this method returns the task from the action (which is still running) | |
| } | |
| } | |
| // 1. Execution Starts | |
| public async T DoStuff(){ | |
| // 2. Calls Transaction | |
| //10. the task is now awaited | |
| return await _session.Transaction(async session=> | |
| { | |
| // 5. Lambda executing | |
| session.Get<Foo>(); | |
| // 6. We hit the await keyword, this causes this lambda to return | |
| await SomeAsyncThingo(); | |
| // 11. The async operation returns, now you are playing with a disposed transaction | |
| session.DoSomethingElse(); | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment