Skip to content

Commit 233c813

Browse files
bugfix: implement IDisposable for dependency injection disposal
otherwise service container throws when disposed
1 parent 77e1369 commit 233c813

File tree

8 files changed

+24
-4
lines changed

8 files changed

+24
-4
lines changed

EntityDb.Abstractions/Snapshots/ISnapshotRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace EntityDb.Abstractions.Snapshots
77
/// Represents a collection of <typeparamref name="TEntity"/> snapshots.
88
/// </summary>
99
/// <typeparam name="TEntity">The type of entity stored in the <see cref="ISnapshotRepository{TEntity}"/>.</typeparam>
10-
public interface ISnapshotRepository<TEntity> : IAsyncDisposable
10+
public interface ISnapshotRepository<TEntity> : IDisposable, IAsyncDisposable
1111
{
1212
/// <summary>
1313
/// Returns a <typeparamref name="TEntity"/> snapshot or <c>default(<typeparamref name="TEntity"/>)</c>.

EntityDb.Abstractions/Transactions/ITransactionRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace EntityDb.Abstractions.Transactions
1111
/// Represents an explicit set of objects which represent a complete history of a set of entities.
1212
/// </summary>
1313
/// <typeparam name="TEntity">The type of entity represented by the objects stored in the <see cref="ITransactionRepository{TEntity}"/>.</typeparam>
14-
public interface ITransactionRepository<TEntity> : IAsyncDisposable
14+
public interface ITransactionRepository<TEntity> : IDisposable, IAsyncDisposable
1515
{
1616
/// <summary>
1717
/// Returns the transaction ids which are found by a source query.

EntityDb.MongoDb/Sessions/IMongoDbSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace EntityDb.MongoDb.Sessions
66
{
7-
internal interface IMongoDbSession : IAsyncDisposable
7+
internal interface IMongoDbSession : IDisposable, IAsyncDisposable
88
{
99
Task<TResult> ExecuteQuery<TResult>(Func<IServiceProvider, IClientSessionHandle?, IMongoDatabase, Task<TResult>> query, TResult defaultResult);
1010
Task<bool> ExecuteCommand(Func<IServiceProvider, IClientSessionHandle, IMongoDatabase, Task> command);

EntityDb.MongoDb/Sessions/MongoDbSession.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ async Task<bool> Abort()
8686
}
8787
}
8888

89+
public void Dispose()
90+
{
91+
DisposeAsync().AsTask().Wait();
92+
}
93+
8994
public async ValueTask DisposeAsync()
9095
{
9196
await Task.Yield();

EntityDb.MongoDb/Transactions/MongoDbTransactionRepository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ await TagDocument.InsertMany
216216
);
217217
}
218218

219+
public void Dispose()
220+
{
221+
DisposeAsync().AsTask().Wait();
222+
}
223+
219224
public async ValueTask DisposeAsync()
220225
{
221226
await _mongoDbSession.DisposeAsync();

EntityDb.Redis/Sessions/IRedisSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace EntityDb.Redis.Sessions
66
{
7-
internal interface IRedisSession : IAsyncDisposable
7+
internal interface IRedisSession : IDisposable, IAsyncDisposable
88
{
99
Task<TResult> ExecuteQuery<TResult>(Func<IServiceProvider, IDatabase, Task<TResult>> query, TResult defaultResult);
1010
Task<bool> ExecuteCommand(Func<IServiceProvider, ITransaction, Task<bool>> command);

EntityDb.Redis/Sessions/RedisSession.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ Task<bool> Abort()
7171
}
7272
}
7373

74+
public void Dispose()
75+
{
76+
DisposeAsync().AsTask().Wait();
77+
}
78+
7479
public async ValueTask DisposeAsync()
7580
{
7681
await Task.Yield();

EntityDb.Redis/Snapshots/RedisSnapshotRepository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public virtual Task<bool> PutSnapshot(Guid entityId, TEntity entity)
6363
);
6464
}
6565

66+
public void Dispose()
67+
{
68+
DisposeAsync().AsTask().Wait();
69+
}
70+
6671
public async virtual ValueTask DisposeAsync()
6772
{
6873
await RedisSession.DisposeAsync();

0 commit comments

Comments
 (0)