Commit a8a837fd authored by Steve Smith's avatar Steve Smith

moved event firing to after savechanges

parent 52e0c59c
......@@ -20,6 +20,9 @@ namespace CleanArchitecture.Infrastructure.Data
public override int SaveChanges()
{
int result = base.SaveChanges();
// dispatch events only if save was successful
var entitiesWithEvents = ChangeTracker.Entries<BaseEntity>()
.Select(e => e.Entity)
.Where(e => e.Events.Any())
......@@ -34,7 +37,8 @@ namespace CleanArchitecture.Infrastructure.Data
_dispatcher.Dispatch(domainEvent);
}
}
return base.SaveChanges();
return result;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment