Created
June 25, 2015 20:16
-
-
Save ramonsmits/9d11e05276fd45763964 to your computer and use it in GitHub Desktop.
NServiceBus Unit of work that calls .SaveChanges on a DbContext using Func<DbContext>
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
busConfiguration.RegisterComponents(r => r.ConfigureComponent<ReceiverDataContext>(DependencyLifecycle.InstancePerUnitOfWork)); | |
busConfiguration.RegisterComponents(r => r.ConfigureComponent<IDbConnection>(b => b.Build<NHibernateStorageContext>().Connection, DependencyLifecycle.InstancePerUnitOfWork)); | |
class DbContextUnitOfWork : IManageUnitsOfWork | |
{ | |
private readonly Func<ReceiverDataContext> createContext; | |
public DbContextUnitOfWork(Func<ReceiverDataContext> createContext) | |
{ | |
this.createContext = createContext; | |
} | |
publicvoid Begin() | |
{ | |
} | |
publicvoid End(Exception ex =null) | |
{ | |
if (ex ==null) createContext().SaveChanges(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment