aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/VNLib.Plugins.Extensions.Data/src/ITransactionalDbContext.cs58
-rw-r--r--lib/VNLib.Plugins.Extensions.Data/src/TransactionalDbContext.cs34
-rw-r--r--lib/VNLib.Plugins.Extensions.Validation/src/ValidationExtensions.cs8
3 files changed, 76 insertions, 24 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Data/src/ITransactionalDbContext.cs b/lib/VNLib.Plugins.Extensions.Data/src/ITransactionalDbContext.cs
new file mode 100644
index 0000000..a699140
--- /dev/null
+++ b/lib/VNLib.Plugins.Extensions.Data/src/ITransactionalDbContext.cs
@@ -0,0 +1,58 @@
+/*
+* Copyright (c) 2022 Vaughn Nugent
+*
+* Library: VNLib
+* Package: VNLib.Plugins.Extensions.Data
+* File: TransactionalDbContext.cs
+*
+* TransactionalDbContext.cs is part of VNLib.Plugins.Extensions.Data which is part of the larger
+* VNLib collection of libraries and utilities.
+*
+* VNLib.Plugins.Extensions.Data is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* VNLib.Plugins.Extensions.Data is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see https://www.gnu.org/licenses/.
+*/
+
+using System.Threading;
+using System.Threading.Tasks;
+
+using Microsoft.EntityFrameworkCore.Storage;
+
+namespace VNLib.Plugins.Extensions.Data
+{
+ /// <summary>
+ /// Represents a database context that can manage concurrency via transactions
+ /// </summary>
+ public interface ITransactionalDbContext
+ {
+ /// <summary>
+ /// The transaction that was opened on the current context
+ /// </summary>
+ IDbContextTransaction? Transaction { get; set; }
+
+ /// <summary>
+ /// Invokes the <see cref="IDbContextTransaction.Commit"/> on the current context
+ /// </summary>
+ Task CommitTransactionAsync(CancellationToken token = default);
+
+ /// <summary>
+ /// Opens a single transaction on the current context. If a transaction is already open,
+ /// it is disposed and a new transaction is begun.
+ /// </summary>
+ Task OpenTransactionAsync(CancellationToken cancellationToken = default);
+
+ /// <summary>
+ /// Invokes the <see cref="IDbContextTransaction.Rollback"/> on the current context
+ /// </summary>
+ Task RollbackTransctionAsync(CancellationToken token = default);
+ }
+} \ No newline at end of file
diff --git a/lib/VNLib.Plugins.Extensions.Data/src/TransactionalDbContext.cs b/lib/VNLib.Plugins.Extensions.Data/src/TransactionalDbContext.cs
index 5824700..e06ac43 100644
--- a/lib/VNLib.Plugins.Extensions.Data/src/TransactionalDbContext.cs
+++ b/lib/VNLib.Plugins.Extensions.Data/src/TransactionalDbContext.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Extensions.Data
@@ -31,22 +31,23 @@ using Microsoft.EntityFrameworkCore.Storage;
namespace VNLib.Plugins.Extensions.Data
{
- public abstract class TransactionalDbContext : DbContext, IAsyncDisposable
+ /// <summary>
+ /// Abstract implementation of <see cref="ITransactionalDbContext"/> that provides a transactional context for database operations
+ /// </summary>
+ public abstract class TransactionalDbContext : DbContext, IAsyncDisposable, ITransactionalDbContext
{
/// <summary>
/// <inheritdoc/>
/// </summary>
protected TransactionalDbContext()
- {}
+ { }
/// <summary>
/// <inheritdoc/>
/// </summary>
protected TransactionalDbContext(DbContextOptions options) : base(options)
- {}
+ { }
- /// <summary>
- /// The transaction that was opened on the current context
- /// </summary>
+ ///<inheritdoc/>
public IDbContextTransaction? Transaction { get; set; }
@@ -58,7 +59,7 @@ namespace VNLib.Plugins.Extensions.Data
Transaction?.Dispose();
base.Dispose();
}
-
+
///<inheritdoc/>
public override async ValueTask DisposeAsync()
{
@@ -71,29 +72,24 @@ namespace VNLib.Plugins.Extensions.Data
}
#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize
- /// <summary>
- /// Opens a single transaction on the current context. If a transaction is already open,
- /// it is disposed and a new transaction is begun.
- /// </summary>
+ ///<inheritdoc/>
public async Task OpenTransactionAsync(CancellationToken cancellationToken = default)
{
//open a new transaction on the current database
this.Transaction = await base.Database.BeginTransactionAsync(cancellationToken);
}
- /// <summary>
- /// Invokes the <see cref="IDbContextTransaction.Commit"/> on the current context
- /// </summary>
+
+ ///<inheritdoc/>
public Task CommitTransactionAsync(CancellationToken token = default)
{
return Transaction != null ? Transaction.CommitAsync(token) : Task.CompletedTask;
}
- /// <summary>
- /// Invokes the <see cref="IDbContextTransaction.Rollback"/> on the current context
- /// </summary>
+
+ ///<inheritdoc/>
public Task RollbackTransctionAsync(CancellationToken token = default)
{
return Transaction != null ? Transaction.RollbackAsync(token) : Task.CompletedTask;
}
-
+
}
} \ No newline at end of file
diff --git a/lib/VNLib.Plugins.Extensions.Validation/src/ValidationExtensions.cs b/lib/VNLib.Plugins.Extensions.Validation/src/ValidationExtensions.cs
index 1734ccb..f277003 100644
--- a/lib/VNLib.Plugins.Extensions.Validation/src/ValidationExtensions.cs
+++ b/lib/VNLib.Plugins.Extensions.Validation/src/ValidationExtensions.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Extensions.Validation
@@ -28,8 +28,6 @@ using System.Diagnostics.CodeAnalysis;
using FluentValidation;
using FluentValidation.Results;
-#nullable enable
-
namespace VNLib.Plugins.Extensions.Validation
{
/// <summary>
@@ -38,7 +36,7 @@ namespace VNLib.Plugins.Extensions.Validation
public static class ValidationExtensions
{
/// <summary>
- /// If <paramref name="assertion"/> evalues to false, sets the specified assertion message
+ /// If <paramref name="assertion"/> evaluates to false, sets the specified assertion message
/// to the <see cref="WebMessage.Result"/> to the specified string
/// </summary>
/// <param name="webm"></param>
@@ -54,9 +52,9 @@ namespace VNLib.Plugins.Extensions.Validation
}
return !assertion;
}
+
/// <summary>
/// Validates the specified instance, and stores errors to the specified <paramref name="webMessage"/>
- /// and sets the <see cref="ValErrWebMessage.IsError"/>
/// </summary>
/// <param name="instance">The instance to validate</param>
/// <param name="validator"></param>