Skip to content

Commit 324865f

Browse files
Refactor (#23)
* refactor: move filter interfaces to abstractions * refactor: do not expose inner repositories on entity repository instead, add a method to get the most recent snapshot, distinguish from method that returns current state * refactor: require a snapshotting strategy to add redis snapshotting * refactor: prune unused query bring your own queries * refactor: move constructing strategy to proper home * refactor: remove reject files * refactor: get snapshot or default, not or construct if there's no snapshot, we want it to return null, not the newly constructed entity * chore: parameter is actually ILogger not IServiceProvider, rename * refactor: snapshotting changes 1. remove PreviousSnapshot from ITransactionCommand 2. test mode passes an object that controls disposal; we need this because we will be separating recording snapshots from pulling them, and end up with two different instances of ISnapshotRepository; it should not remove the entries created until all instances have been disposed * refactor: stop injecting IServiceProvider ask for the required dependencies explicitly * feature: async transaction subscriber in test mode, will run synchronously * feature: snapshotting transaction subscriber store transaction snapshots asynchronously, don't block or allow a failure to cause problems :)
1 parent f540d20 commit 324865f

File tree

65 files changed

+978
-932
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+978
-932
lines changed
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using EntityDb.Abstractions.Snapshots;
2-
using EntityDb.Abstractions.Transactions;
1+
using EntityDb.Abstractions.Transactions;
32
using System;
43
using System.Threading.Tasks;
54

@@ -11,24 +10,25 @@ namespace EntityDb.Abstractions.Entities
1110
/// <typeparam name="TEntity">The type of the entity.</typeparam>
1211
public interface IEntityRepository<TEntity> : IDisposable, IAsyncDisposable
1312
{
14-
/// <inheritdoc cref="ITransactionRepository{TEntity}" />
15-
ITransactionRepository<TEntity> TransactionRepository { get; }
16-
17-
/// <inheritdoc cref="ISnapshotRepository{TEntity}" />
18-
ISnapshotRepository<TEntity>? SnapshotRepository { get; }
19-
2013
/// <summary>
21-
/// Returns a <typeparamref name="TEntity" /> snapshot or <c>default(<typeparamref name="TEntity" />)</c>.
14+
/// Returns the most recent snapshot of a <typeparamref name="TEntity" /> or <c>default(<typeparamref name="TEntity" />)</c>.
15+
/// </summary>
16+
/// <param name="entityId">The id of the entity.</param>
17+
/// <returns>The most recent snapshot of a <typeparamref name="TEntity" /> or constructs a new <typeparamref name="TEntity" />.</returns>
18+
Task<TEntity?> GetSnapshotOrDefault(Guid entityId);
19+
20+
/// <summary>
21+
/// Returns the current state of a <typeparamref name="TEntity" /> or constructs a new <typeparamref name="TEntity" />.
2222
/// </summary>
2323
/// <param name="entityId">The id of the entity.</param>
24-
/// <returns>A <typeparamref name="TEntity" /> snapshot or <c>default(<typeparamref name="TEntity" />)</c>.</returns>
25-
Task<TEntity> Get(Guid entityId);
24+
/// <returns>The current state of a <typeparamref name="TEntity" /> or constructs a new <typeparamref name="TEntity" />.</returns>
25+
Task<TEntity> GetCurrentOrConstruct(Guid entityId);
2626

2727
/// <summary>
2828
/// Inserts a single transaction with an atomic commit.
2929
/// </summary>
3030
/// <param name="transaction">The transaction.</param>
31-
/// <returns><c>true</c> if the insert suceeded, or <c>false</c> if the insert failed.</returns>
32-
Task<bool> Put(ITransaction<TEntity> transaction);
31+
/// <returns><c>true</c> if the insert succeeded, or <c>false</c> if the insert failed.</returns>
32+
Task<bool> PutTransaction(ITransaction<TEntity> transaction);
3333
}
3434
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using EntityDb.Abstractions.Snapshots;
2+
using EntityDb.Abstractions.Transactions;
3+
using System.Threading.Tasks;
4+
5+
namespace EntityDb.Abstractions.Entities
6+
{
7+
public interface IEntityRepositoryFactory<TEntity>
8+
{
9+
Task<IEntityRepository<TEntity>> CreateRepository(ITransactionSessionOptions transactionSessionOptions,
10+
ISnapshotSessionOptions? snapshotSessionOptions = null);
11+
}
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using EntityDb.Abstractions.Queries.FilterBuilders;
2+
3+
namespace EntityDb.Abstractions.Queries.Filters
4+
{
5+
/// <summary>
6+
/// Represents a type that supplies filtering for a <see cref="ICommandQuery" />.
7+
/// </summary>
8+
public interface ICommandFilter
9+
{
10+
/// <summary>
11+
/// Returns a <typeparamref name="TFilter" /> built from a command filter builder.
12+
/// </summary>
13+
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
14+
/// <param name="builder">The command filter builder.</param>
15+
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
16+
TFilter GetFilter<TFilter>(ICommandFilterBuilder<TFilter> builder);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using EntityDb.Abstractions.Queries.FilterBuilders;
2+
3+
namespace EntityDb.Abstractions.Queries.Filters
4+
{
5+
/// <summary>
6+
/// Represents a type that supplies filtering for a <see cref="IFactQuery" />.
7+
/// </summary>
8+
public interface IFactFilter
9+
{
10+
/// <summary>
11+
/// Returns a <typeparamref name="TFilter" /> built from a fact filter builder.
12+
/// </summary>
13+
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
14+
/// <param name="builder">The fact filter builder.</param>
15+
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
16+
TFilter GetFilter<TFilter>(IFactFilterBuilder<TFilter> builder);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using EntityDb.Abstractions.Queries.FilterBuilders;
2+
3+
namespace EntityDb.Abstractions.Queries.Filters
4+
{
5+
/// <summary>
6+
/// Represents a type that supplies filtering for a <see cref="ILeaseQuery" />.
7+
/// </summary>
8+
public interface ILeaseFilter
9+
{
10+
/// <summary>
11+
/// Returns a <typeparamref name="TFilter" /> built from a lease filter builder.
12+
/// </summary>
13+
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
14+
/// <param name="builder">The lease filter builder.</param>
15+
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
16+
TFilter GetFilter<TFilter>(ILeaseFilterBuilder<TFilter> builder);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using EntityDb.Abstractions.Queries.FilterBuilders;
2+
3+
namespace EntityDb.Abstractions.Queries.Filters
4+
{
5+
/// <summary>
6+
/// Represents a type that supplies filtering for a <see cref="ISourceQuery" />.
7+
/// </summary>
8+
public interface ISourceFilter
9+
{
10+
/// <summary>
11+
/// Returns a <typeparamref name="TFilter" /> built from a source filter builder.
12+
/// </summary>
13+
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
14+
/// <param name="builder">The source filter builder.</param>
15+
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
16+
TFilter GetFilter<TFilter>(ISourceFilterBuilder<TFilter> builder);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using EntityDb.Abstractions.Queries.FilterBuilders;
2+
3+
namespace EntityDb.Abstractions.Queries.Filters
4+
{
5+
/// <summary>
6+
/// Represents a type that supplies filtering for a <see cref="ITagQuery" />.
7+
/// </summary>
8+
public interface ITagFilter
9+
{
10+
/// <summary>
11+
/// Returns a <typeparamref name="TFilter" /> built from a tag filter builder.
12+
/// </summary>
13+
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
14+
/// <param name="builder">The tag filter builder.</param>
15+
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
16+
TFilter GetFilter<TFilter>(ITagFilterBuilder<TFilter> builder);
17+
}
18+
}

src/EntityDb.Abstractions/Queries/ICommandQuery.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
using EntityDb.Abstractions.Queries.FilterBuilders;
1+
using EntityDb.Abstractions.Queries.Filters;
22
using EntityDb.Abstractions.Queries.SortBuilders;
33

44
namespace EntityDb.Abstractions.Queries
55
{
66
/// <summary>
77
/// Abstracts a query on commands.
88
/// </summary>
9-
public interface ICommandQuery : IQuery
9+
public interface ICommandQuery : IQuery, ICommandFilter
1010
{
11-
/// <summary>
12-
/// Returns a <typeparamref name="TFilter" /> built from a command filter builder.
13-
/// </summary>
14-
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
15-
/// <param name="builder">The command filter builder.</param>
16-
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
17-
TFilter GetFilter<TFilter>(ICommandFilterBuilder<TFilter> builder);
18-
1911
/// <summary>
2012
/// Returns a <typeparamref name="TSort" /> built from a command sort builder.
2113
/// </summary>

src/EntityDb.Abstractions/Queries/IFactQuery.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
using EntityDb.Abstractions.Queries.FilterBuilders;
1+
using EntityDb.Abstractions.Queries.Filters;
22
using EntityDb.Abstractions.Queries.SortBuilders;
33

44
namespace EntityDb.Abstractions.Queries
55
{
66
/// <summary>
77
/// Abstracts a query on facts.
88
/// </summary>
9-
public interface IFactQuery : IQuery
9+
public interface IFactQuery : IQuery, IFactFilter
1010
{
11-
/// <summary>
12-
/// Returns a <typeparamref name="TFilter" /> built from a fact filter builder.
13-
/// </summary>
14-
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
15-
/// <param name="builder">The fact filter builder.</param>
16-
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
17-
TFilter GetFilter<TFilter>(IFactFilterBuilder<TFilter> builder);
18-
1911
/// <summary>
2012
/// Returns a <typeparamref name="TSort" /> built from a fact sort builder.
2113
/// </summary>

src/EntityDb.Abstractions/Queries/ILeaseQuery.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
using EntityDb.Abstractions.Queries.FilterBuilders;
1+
using EntityDb.Abstractions.Queries.Filters;
22
using EntityDb.Abstractions.Queries.SortBuilders;
33

44
namespace EntityDb.Abstractions.Queries
55
{
66
/// <summary>
77
/// Abstracts a query on leases.
88
/// </summary>
9-
public interface ILeaseQuery : IQuery
9+
public interface ILeaseQuery : IQuery, ILeaseFilter
1010
{
11-
/// <summary>
12-
/// Returns a <typeparamref name="TFilter" /> built from a lease filter builder.
13-
/// </summary>
14-
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
15-
/// <param name="builder">The lease filter builder.</param>
16-
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
17-
TFilter GetFilter<TFilter>(ILeaseFilterBuilder<TFilter> builder);
18-
1911
/// <summary>
2012
/// Returns a <typeparamref name="TSort" /> built from a lease sort builder.
2113
/// </summary>

0 commit comments

Comments
 (0)