Update: Repository Monitor Deferred Actions
Defer code in 'before commit' to run 'after commit'
This commit is contained in:
@@ -12,11 +12,13 @@ namespace Disco.Data.Repository.Monitor
|
||||
public class RepositoryMonitorEvent
|
||||
{
|
||||
[JsonIgnore]
|
||||
internal ObjectStateEntry objectEntryState { get; set; }
|
||||
internal ObjectStateEntry objectEntryState;
|
||||
[JsonIgnore]
|
||||
internal DbEntityEntry dbEntityState { get; set; }
|
||||
internal DbEntityEntry dbEntityState;
|
||||
[JsonIgnore]
|
||||
internal bool afterCommit { get; set; }
|
||||
internal bool afterCommit;
|
||||
[JsonIgnore]
|
||||
internal List<Action<RepositoryMonitorEvent>> executeAfterCommit;
|
||||
|
||||
[JsonIgnore]
|
||||
public DiscoDataContext dbContext { get; set; }
|
||||
@@ -44,7 +46,7 @@ namespace Disco.Data.Repository.Monitor
|
||||
public T GetPreviousPropertyValue<T>(string PropertyName)
|
||||
{
|
||||
if (afterCommit)
|
||||
throw new InvalidOperationException("Unable to determine property values after repository commit");
|
||||
throw new InvalidOperationException("Unable to determine property values after repository commit, use a deferred action instead");
|
||||
else
|
||||
return (T)dbEntityState.OriginalValues[PropertyName];
|
||||
}
|
||||
@@ -52,5 +54,20 @@ namespace Disco.Data.Repository.Monitor
|
||||
{
|
||||
return (T)dbEntityState.CurrentValues[PropertyName];
|
||||
}
|
||||
|
||||
public void ExecuteAfterCommit(Action<RepositoryMonitorEvent> action){
|
||||
if (afterCommit)
|
||||
{
|
||||
// Execute Immediately
|
||||
action.Invoke(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Defer Execution
|
||||
if (executeAfterCommit == null)
|
||||
executeAfterCommit = new List<Action<RepositoryMonitorEvent>>();
|
||||
executeAfterCommit.Add(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user