Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigger transaction-commited-event when dbcontextcollection savechanges #54

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DbContextScope.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo Application", "DemoApplication\Demo Application.csproj", "{977FC0C6-4FDF-4DD9-AAC0-456D4D79C96C}"
EndProject
Expand Down
16 changes: 16 additions & 0 deletions Mehdime.Entity/Implementations/DbContextCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public TDbContext Get<TDbContext>() where TDbContext : DbContext
return _initializedDbContexts[requestedType] as TDbContext;
}

/// <summary>
/// When Transaction Committed
/// </summary>
public event EventHandler<EventArgs> TransactionCommitted;

public int Commit()
{
if (_disposed)
Expand Down Expand Up @@ -140,6 +145,8 @@ public int Commit()
if (lastError != null)
lastError.Throw(); // Re-throw while maintaining the exception's original stack track

OnTransactionCommitted(new EventArgs());

return c;
}

Expand Down Expand Up @@ -192,6 +199,8 @@ public async Task<int> CommitAsync(CancellationToken cancelToken)
if (lastError != null)
lastError.Throw(); // Re-throw while maintaining the exception's original stack track

OnTransactionCommitted(new EventArgs());

return c;
}

Expand Down Expand Up @@ -281,5 +290,12 @@ private static TValue GetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue>
TValue value;
return dictionary.TryGetValue(key, out value) ? value : default(TValue);
}

protected void OnTransactionCommitted(EventArgs e)
{
var temp = Volatile.Read(ref TransactionCommitted);

temp?.Invoke(this, e);
}
}
}
5 changes: 5 additions & 0 deletions Mehdime.Entity/Interfaces/IDbContextCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public interface IDbContextCollection : IDisposable
/// Get or create a DbContext instance of the specified type.
/// </summary>
TDbContext Get<TDbContext>() where TDbContext : DbContext;

/// <summary>
/// When Transaction Committed
/// </summary>
event EventHandler<EventArgs> TransactionCommitted;
}
}
4 changes: 2 additions & 2 deletions Mehdime.Entity/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.2")]
[assembly: AssemblyFileVersion("1.0.0.2")]