From 5c7682ea26c53a9a50e42f5c2f9a69b8794d698d Mon Sep 17 00:00:00 2001 From: Chris Simmons Date: Sun, 11 Jan 2026 11:33:38 -0800 Subject: [PATCH] IUnitOfWork --- NetChris.Core/Patterns/IUnitOfWork.cs | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 NetChris.Core/Patterns/IUnitOfWork.cs diff --git a/NetChris.Core/Patterns/IUnitOfWork.cs b/NetChris.Core/Patterns/IUnitOfWork.cs new file mode 100644 index 0000000..d666c0f --- /dev/null +++ b/NetChris.Core/Patterns/IUnitOfWork.cs @@ -0,0 +1,29 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace NetChris.Core.Patterns; + +/// +/// Presents a unit of work interface to coordinate a unit-of-work pattern operation against a data store. +/// +/// +/// +/// There is no prescribed implementation of this of course. However the primary use of this will be to wrap the operations +/// of an Entity Framework DbContext. And even though the DbContext's SaveChanges/Async operations constitute a unit +/// of work in and of themselves, it's important to have a separate handle on the over-arching unit of work for: +/// +/// Having an abstraction to use for testing in concert with repository abstractions. +/// Handle the common exceptions that can occur when saving changes to the database, and then wrap them in well-known exceptions. +/// Allow the ability to save/commit the unit of work without needing to reference the DbContext +/// +/// +/// +public interface IUnitOfWork +{ + /// + /// Commit the unit of work + /// + /// The cancellation token + /// A task that represents the asynchronous save operation. The task result contains the number of state entries written to the database. + Task SaveChangesAsync(CancellationToken cancellationToken = default); +} \ No newline at end of file