-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Transaction Support and Upgrade MongoDriver to V3
- Loading branch information
Showing
22 changed files
with
426 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: 2 | ||
updates: | ||
|
||
# Maintain dependencies for Nuget Packages | ||
- package-ecosystem: nuget | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 25 | ||
|
||
# Maintain dependencies for GitHub Actions | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
src/Myrtle.Abstractions/Exceptions/MongoTransactionAlreadyStartedException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Myrtle.Abstractions.Exceptions; | ||
|
||
/// <summary> | ||
/// The exception thrown when attempting to start a MongoDB transaction that is already active. | ||
/// </summary> | ||
public sealed class MongoTransactionAlreadyStartedException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MongoTransactionAlreadyStartedException"/> class. | ||
/// </summary> | ||
public MongoTransactionAlreadyStartedException() | ||
: base("A MongoDB transaction is already in progress.") | ||
{ | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Myrtle.Abstractions/Exceptions/MongoTransactionNotStartedException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Myrtle.Abstractions.Exceptions; | ||
|
||
/// <summary> | ||
/// The exception thrown when attempting to perform operations on a MongoDB transaction that hasn't been started. | ||
/// </summary> | ||
public sealed class MongoTransactionNotStartedException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MongoTransactionNotStartedException"/> class. | ||
/// </summary> | ||
public MongoTransactionNotStartedException() | ||
: base("No MongoDB transaction has been started. Call StartAsync before performing transaction operations.") | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
namespace Myrtle.Abstractions; | ||
|
||
using MongoDB.Driver; | ||
using Exceptions; | ||
|
||
/// <summary> | ||
/// Represents a context for managing the lifecycle of a MongoDB transaction. | ||
/// Ensures proper handling of MongoDB transactions, including starting, committing, and cleaning up resources. | ||
/// Implements IAsyncDisposable for automatic cleanup of transaction resources. | ||
/// </summary> | ||
/// <remarks> | ||
/// This context should be used within a using block to ensure proper resource cleanup. | ||
/// All operations within the transaction should be performed between calls to StartAsync and CommitAsync. | ||
/// If an exception occurs, the transaction should be aborted using AbortAsync. | ||
/// </remarks> | ||
public interface IMongoTransactionContext : IAsyncDisposable | ||
{ | ||
/// <summary> | ||
/// Gets a value indicating whether a transaction is currently active within this context. | ||
/// </summary> | ||
/// <value> | ||
/// True if a transaction has been started and not yet committed or aborted; otherwise, false. | ||
/// </value> | ||
bool IsActive { get; } | ||
|
||
/// <summary> | ||
/// Gets the current MongoDB session handle associated with this transaction context. | ||
/// </summary> | ||
/// <value> | ||
/// The MongoDB client session handle managing the current transaction. | ||
/// </value> | ||
/// <exception cref="MongoTransactionNotStartedException"> | ||
/// Thrown when accessing the session before starting a transaction. | ||
/// </exception> | ||
IClientSessionHandle Session { get; } | ||
|
||
/// <summary> | ||
/// Starts a new MongoDB transaction within this context. | ||
/// </summary> | ||
/// <param name="cancellationToken">A token to cancel the async operation.</param> | ||
/// <returns>A task representing the asynchronous operation.</returns> | ||
/// <exception cref="MongoTransactionAlreadyStartedException"> | ||
/// Thrown when attempting to start a transaction while another is already active. | ||
/// </exception> | ||
/// <exception cref="MongoException"> | ||
/// Thrown when the MongoDB server encounters an error while starting the transaction. | ||
/// </exception> | ||
Task StartAsync(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Commits the current MongoDB transaction. | ||
/// </summary> | ||
/// <param name="cancellationToken">A token to cancel the async operation.</param> | ||
/// <returns>A task representing the asynchronous operation.</returns> | ||
/// <exception cref="MongoTransactionNotStartedException"> | ||
/// Thrown when attempting to commit a transaction that hasn't been started. | ||
/// </exception> | ||
/// <exception cref="MongoException"> | ||
/// Thrown when the MongoDB server encounters an error while committing the transaction. | ||
/// </exception> | ||
Task CommitAsync(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Aborts the current MongoDB transaction. | ||
/// </summary> | ||
/// <param name="cancellationToken">A token to cancel the async operation.</param> | ||
/// <returns>A task representing the asynchronous operation.</returns> | ||
/// <exception cref="MongoTransactionNotStartedException"> | ||
/// Thrown when attempting to abort a transaction that hasn't been started. | ||
/// </exception> | ||
/// <exception cref="MongoException"> | ||
/// Thrown when the MongoDB server encounters an error while aborting the transaction. | ||
/// </exception> | ||
Task AbortAsync(CancellationToken cancellationToken = default); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.