Skip to content

Instantly share code, notes, and snippets.

@ramonsmits
Created June 25, 2015 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramonsmits/9d11e05276fd45763964 to your computer and use it in GitHub Desktop.
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>
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