Skip to content

Commit

Permalink
Refactor (#23)
Browse files Browse the repository at this point in the history
* 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 :)
  • Loading branch information
the-avid-engineer authored Oct 6, 2021
1 parent f540d20 commit 324865f
Show file tree
Hide file tree
Showing 65 changed files with 978 additions and 932 deletions.
26 changes: 13 additions & 13 deletions src/EntityDb.Abstractions/Entities/IEntityRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EntityDb.Abstractions.Snapshots;
using EntityDb.Abstractions.Transactions;
using EntityDb.Abstractions.Transactions;
using System;
using System.Threading.Tasks;

Expand All @@ -11,24 +10,25 @@ namespace EntityDb.Abstractions.Entities
/// <typeparam name="TEntity">The type of the entity.</typeparam>
public interface IEntityRepository<TEntity> : IDisposable, IAsyncDisposable
{
/// <inheritdoc cref="ITransactionRepository{TEntity}" />
ITransactionRepository<TEntity> TransactionRepository { get; }

/// <inheritdoc cref="ISnapshotRepository{TEntity}" />
ISnapshotRepository<TEntity>? SnapshotRepository { get; }

/// <summary>
/// Returns a <typeparamref name="TEntity" /> snapshot or <c>default(<typeparamref name="TEntity" />)</c>.
/// Returns the most recent snapshot of a <typeparamref name="TEntity" /> or <c>default(<typeparamref name="TEntity" />)</c>.
/// </summary>
/// <param name="entityId">The id of the entity.</param>
/// <returns>The most recent snapshot of a <typeparamref name="TEntity" /> or constructs a new <typeparamref name="TEntity" />.</returns>
Task<TEntity?> GetSnapshotOrDefault(Guid entityId);

/// <summary>
/// Returns the current state of a <typeparamref name="TEntity" /> or constructs a new <typeparamref name="TEntity" />.
/// </summary>
/// <param name="entityId">The id of the entity.</param>
/// <returns>A <typeparamref name="TEntity" /> snapshot or <c>default(<typeparamref name="TEntity" />)</c>.</returns>
Task<TEntity> Get(Guid entityId);
/// <returns>The current state of a <typeparamref name="TEntity" /> or constructs a new <typeparamref name="TEntity" />.</returns>
Task<TEntity> GetCurrentOrConstruct(Guid entityId);

/// <summary>
/// Inserts a single transaction with an atomic commit.
/// </summary>
/// <param name="transaction">The transaction.</param>
/// <returns><c>true</c> if the insert suceeded, or <c>false</c> if the insert failed.</returns>
Task<bool> Put(ITransaction<TEntity> transaction);
/// <returns><c>true</c> if the insert succeeded, or <c>false</c> if the insert failed.</returns>
Task<bool> PutTransaction(ITransaction<TEntity> transaction);
}
}
12 changes: 12 additions & 0 deletions src/EntityDb.Abstractions/Entities/IEntityRepositoryFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using EntityDb.Abstractions.Snapshots;
using EntityDb.Abstractions.Transactions;
using System.Threading.Tasks;

namespace EntityDb.Abstractions.Entities
{
public interface IEntityRepositoryFactory<TEntity>
{
Task<IEntityRepository<TEntity>> CreateRepository(ITransactionSessionOptions transactionSessionOptions,
ISnapshotSessionOptions? snapshotSessionOptions = null);
}
}
18 changes: 18 additions & 0 deletions src/EntityDb.Abstractions/Queries/Filters/ICommandFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using EntityDb.Abstractions.Queries.FilterBuilders;

namespace EntityDb.Abstractions.Queries.Filters
{
/// <summary>
/// Represents a type that supplies filtering for a <see cref="ICommandQuery" />.
/// </summary>
public interface ICommandFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a command filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The command filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ICommandFilterBuilder<TFilter> builder);
}
}
18 changes: 18 additions & 0 deletions src/EntityDb.Abstractions/Queries/Filters/IFactFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using EntityDb.Abstractions.Queries.FilterBuilders;

namespace EntityDb.Abstractions.Queries.Filters
{
/// <summary>
/// Represents a type that supplies filtering for a <see cref="IFactQuery" />.
/// </summary>
public interface IFactFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a fact filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The fact filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(IFactFilterBuilder<TFilter> builder);
}
}
18 changes: 18 additions & 0 deletions src/EntityDb.Abstractions/Queries/Filters/ILeaseFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using EntityDb.Abstractions.Queries.FilterBuilders;

namespace EntityDb.Abstractions.Queries.Filters
{
/// <summary>
/// Represents a type that supplies filtering for a <see cref="ILeaseQuery" />.
/// </summary>
public interface ILeaseFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a lease filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The lease filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ILeaseFilterBuilder<TFilter> builder);
}
}
18 changes: 18 additions & 0 deletions src/EntityDb.Abstractions/Queries/Filters/ISourceFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using EntityDb.Abstractions.Queries.FilterBuilders;

namespace EntityDb.Abstractions.Queries.Filters
{
/// <summary>
/// Represents a type that supplies filtering for a <see cref="ISourceQuery" />.
/// </summary>
public interface ISourceFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a source filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The source filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ISourceFilterBuilder<TFilter> builder);
}
}
18 changes: 18 additions & 0 deletions src/EntityDb.Abstractions/Queries/Filters/ITagFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using EntityDb.Abstractions.Queries.FilterBuilders;

namespace EntityDb.Abstractions.Queries.Filters
{
/// <summary>
/// Represents a type that supplies filtering for a <see cref="ITagQuery" />.
/// </summary>
public interface ITagFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a tag filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The tag filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ITagFilterBuilder<TFilter> builder);
}
}
12 changes: 2 additions & 10 deletions src/EntityDb.Abstractions/Queries/ICommandQuery.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
using EntityDb.Abstractions.Queries.FilterBuilders;
using EntityDb.Abstractions.Queries.Filters;
using EntityDb.Abstractions.Queries.SortBuilders;

namespace EntityDb.Abstractions.Queries
{
/// <summary>
/// Abstracts a query on commands.
/// </summary>
public interface ICommandQuery : IQuery
public interface ICommandQuery : IQuery, ICommandFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a command filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The command filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ICommandFilterBuilder<TFilter> builder);

/// <summary>
/// Returns a <typeparamref name="TSort" /> built from a command sort builder.
/// </summary>
Expand Down
12 changes: 2 additions & 10 deletions src/EntityDb.Abstractions/Queries/IFactQuery.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
using EntityDb.Abstractions.Queries.FilterBuilders;
using EntityDb.Abstractions.Queries.Filters;
using EntityDb.Abstractions.Queries.SortBuilders;

namespace EntityDb.Abstractions.Queries
{
/// <summary>
/// Abstracts a query on facts.
/// </summary>
public interface IFactQuery : IQuery
public interface IFactQuery : IQuery, IFactFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a fact filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The fact filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(IFactFilterBuilder<TFilter> builder);

/// <summary>
/// Returns a <typeparamref name="TSort" /> built from a fact sort builder.
/// </summary>
Expand Down
12 changes: 2 additions & 10 deletions src/EntityDb.Abstractions/Queries/ILeaseQuery.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
using EntityDb.Abstractions.Queries.FilterBuilders;
using EntityDb.Abstractions.Queries.Filters;
using EntityDb.Abstractions.Queries.SortBuilders;

namespace EntityDb.Abstractions.Queries
{
/// <summary>
/// Abstracts a query on leases.
/// </summary>
public interface ILeaseQuery : IQuery
public interface ILeaseQuery : IQuery, ILeaseFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a lease filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The lease filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ILeaseFilterBuilder<TFilter> builder);

/// <summary>
/// Returns a <typeparamref name="TSort" /> built from a lease sort builder.
/// </summary>
Expand Down
12 changes: 2 additions & 10 deletions src/EntityDb.Abstractions/Queries/ISourceQuery.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
using EntityDb.Abstractions.Queries.FilterBuilders;
using EntityDb.Abstractions.Queries.Filters;
using EntityDb.Abstractions.Queries.SortBuilders;

namespace EntityDb.Abstractions.Queries
{
/// <summary>
/// Abstracts a query on sources.
/// </summary>
public interface ISourceQuery : IQuery
public interface ISourceQuery : IQuery, ISourceFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a source filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The source filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ISourceFilterBuilder<TFilter> builder);

/// <summary>
/// Returns a <typeparamref name="TSort" /> built from a source sort builder.
/// </summary>
Expand Down
12 changes: 2 additions & 10 deletions src/EntityDb.Abstractions/Queries/ITagQuery.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
using EntityDb.Abstractions.Queries.FilterBuilders;
using EntityDb.Abstractions.Queries.Filters;
using EntityDb.Abstractions.Queries.SortBuilders;

namespace EntityDb.Abstractions.Queries
{
/// <summary>
/// Abstracts a query on tags.
/// </summary>
public interface ITagQuery : IQuery
public interface ITagQuery : IQuery, ITagFilter
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> built from a tag filter builder.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
/// <param name="builder">The tag filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ITagFilterBuilder<TFilter> builder);

/// <summary>
/// Returns a <typeparamref name="TSort" /> built from a tag sort builder.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions src/EntityDb.Abstractions/Strategies/IAuthorizingStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public interface IAuthorizingStrategy<TEntity>
/// </summary>
/// <param name="entity">The entity.</param>
/// <param name="command">The command.</param>
/// <param name="agent">The agent.</param>
/// <returns><c>true</c> if execution is authorized, or <c>false</c> if execution is not authorized.</returns>
bool IsAuthorized(TEntity entity, ICommand<TEntity> command, IAgent agent);
bool IsAuthorized(TEntity entity, ICommand<TEntity> command);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// Represents a type used to determine if the next version of an entity should be put into snapshot storage.
/// </summary>
/// <typeparam name="TEntity">The type of the entity that can be put into snapshot storage.</typeparam>
public interface ISnapshottingStrategy<TEntity>
public interface ISnapshottingStrategy<in TEntity>
{
/// <summary>
/// Determines if the next version of an entity should be put into snapshot storage.
Expand Down
5 changes: 0 additions & 5 deletions src/EntityDb.Abstractions/Transactions/ITransactionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ namespace EntityDb.Abstractions.Transactions
/// <typeparam name="TEntity">The type of entity to be modified.</typeparam>
public interface ITransactionCommand<TEntity>
{
/// <summary>
/// A snapshot of the entity before the command.
/// </summary>
TEntity? PreviousSnapshot { get; }

/// <summary>
/// A snapshot of the entity after the command.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/EntityDb.Abstractions/Transactions/ITransactionSubscriber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace EntityDb.Abstractions.Transactions
{
/// <summary>
///
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public interface ITransactionSubscriber<TEntity>
{
/// <summary>
/// Foo
/// </summary>
/// <param name="transaction"></param>
void Notify(ITransaction<TEntity> transaction);
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 324865f

Please sign in to comment.