Skip to content

Commit 4254232

Browse files
authored
IUnitOfWork (#24)
1 parent a4b7066 commit 4254232

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
4+
namespace NetChris.Core.Patterns;
5+
6+
/// <summary>
7+
/// Presents a unit of work interface to coordinate a unit-of-work pattern operation against a data store.
8+
/// </summary>
9+
/// <remarks>
10+
/// <para>
11+
/// There is no prescribed implementation of this of course. However the primary use of this will be to wrap the operations
12+
/// of an Entity Framework DbContext. And even though the DbContext's SaveChanges/Async operations constitute a unit
13+
/// of work in and of themselves, it's important to have a separate handle on the over-arching unit of work for:
14+
/// <list type="bullet">
15+
/// <item>Having an abstraction to use for testing in concert with repository abstractions.</item>
16+
/// <item>Handle the common exceptions that can occur when saving changes to the database, and then wrap them in well-known exceptions.</item>
17+
/// <item>Allow the ability to save/commit the unit of work without needing to reference the DbContext</item>
18+
/// </list>
19+
/// </para>
20+
/// </remarks>
21+
public interface IUnitOfWork
22+
{
23+
/// <summary>
24+
/// Commit the unit of work
25+
/// </summary>
26+
/// <param name="cancellationToken">The cancellation token</param>
27+
/// <returns>A task that represents the asynchronous save operation. The task result contains the number of state entries written to the database.</returns>
28+
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
29+
}

0 commit comments

Comments
 (0)