11using System ;
2+ using System . Threading ;
3+ using System . Threading . Tasks ;
24
35namespace Light . SharedCore . DatabaseAccessAbstractions ;
46
57/// <summary>
68/// <para>
7- /// PLEASE REMEMBER: database calls should be performed asynchronously
8- /// by default, especially in service apps to avoid blocking threads.
9- /// Consider using the <see cref="IAsyncSession" /> interface instead .
9+ /// Represents the base interface for an asynchronous session to a database that manipulates data. This means that
10+ /// the implementation will either use a single dedicated transaction in the case of ADO.NET or Micro-ORMs
11+ /// to ensure ACID properties, or the change tracking capabilities of a full ORM like Entity Framework Core .
1012/// </para>
1113/// <para>
12- /// Represents a synchronous session to a database. This means that
13- /// the implementation will either use a single dedicated transaction in the case of ADO.NET or Micro-ORMs
14- /// to ensure ACID properties, or the Change Tracking capabilities of a full ORM like Entity Framework Core. The
15- /// connection to the database can be terminated by calling
16- /// <see cref="IDisposable.Dispose" />. Changes can be saved or committed
17- /// to the database by calling <see cref="SaveChanges" />.
18- /// If your session does not manipulate data, consider deriving your session abstraction from
19- /// the <see cref="IDisposable" /> interface instead.
14+ /// The connection to the database can be terminated by calling
15+ /// <see cref="IAsyncDisposable.DisposeAsync" />, the underlying transaction
16+ /// will be automatically rolled back if <see cref="SaveChangesAsync" /> was not called beforehand.
17+ /// </para>
18+ /// <para>
19+ /// If you don't want the caller to explicitly commit the changes, consider deriving your session from
20+ /// <see cref="IAsyncDisposable"/> directly.
2021/// </para>
2122/// </summary>
2223/// <remarks>
@@ -26,10 +27,11 @@ namespace Light.SharedCore.DatabaseAccessAbstractions;
2627/// to do Change Tracking which plain ADO.NET and all Micro-ORMs do not support. For this reason,
2728/// we chose the term "session" instead of "Unit of Work", also because it is simpler to use in daily life.
2829/// </remarks>
29- public interface ISession : IDisposable
30+ public interface ISession : IAsyncDisposable
3031{
3132 /// <summary>
32- /// Writes or commits all changes that occurred during the session to the target database.
33+ /// Commits all changes to the database.
3334 /// </summary>
34- void SaveChanges ( ) ;
35+ /// <param name="cancellationToken">The token to cancel this asynchronous operation (optional).</param>
36+ Task SaveChangesAsync ( CancellationToken cancellationToken = default ) ;
3537}
0 commit comments