Skip to content

Commit 0552491

Browse files
feature: void transaction repository
1 parent 81db506 commit 0552491

File tree

6 files changed

+203
-1
lines changed

6 files changed

+203
-1
lines changed

EntityDb.Void/EntityDb.Void.csproj

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<!--Application-->
4+
<PropertyGroup>
5+
<OutputType>Library</OutputType>
6+
<TargetFramework>net5.0</TargetFramework>
7+
<LangVersion>9.0</LangVersion>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<!--Build-->
12+
<PropertyGroup>
13+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
14+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
15+
</PropertyGroup>
16+
17+
<!--Package-->
18+
<PropertyGroup>
19+
<IsPackable>true</IsPackable>
20+
<IncludeSymbols>true</IncludeSymbols>
21+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
22+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
23+
<Authors>Chris Philips</Authors>
24+
<Company>entitydb.io</Company>
25+
<Copyright>2021 © entitydb.io</Copyright>
26+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
27+
<RepositoryUrl>https://github.com/entitydb-io/entitydb</RepositoryUrl>
28+
<RepositoryType>git</RepositoryType>
29+
<NeutralLanguage>en</NeutralLanguage>
30+
<PackageTags>EntityDb EventSourcing DDD CQRS</PackageTags>
31+
<Description>An implementation of the EntityDb Transaction Repository interface, specifically made for non-persistent history.</Description>
32+
</PropertyGroup>
33+
34+
<ItemGroup>
35+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
36+
</ItemGroup>
37+
38+
<ItemGroup>
39+
<ProjectReference Include="..\EntityDb.Common\EntityDb.Common.csproj" />
40+
</ItemGroup>
41+
42+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using EntityDb.Abstractions.Transactions;
2+
using EntityDb.Void.Transactions;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace EntityDb.MongoDb.Extensions
7+
{
8+
/// <summary>
9+
/// Extensions for service collections.
10+
/// </summary>
11+
public static class IServiceCollectionExtensions
12+
{
13+
/// <summary>
14+
/// Adds a production-ready implementation of <see cref="ITransactionRepositoryFactory{TEntity}"/> to a service collection.
15+
/// </summary>
16+
/// <typeparam name="TEntity">The type of the entity represented in the repository.</typeparam>
17+
/// <param name="serviceCollection">The service collection.</param>
18+
/// <remarks>
19+
/// This repository does not do anything.
20+
/// </remarks>
21+
[ExcludeFromCodeCoverage(Justification = "Tests use TestMode.")]
22+
public static void AddVoidTransactions<TEntity>(this IServiceCollection serviceCollection)
23+
{
24+
serviceCollection.AddScoped<ITransactionRepositoryFactory<TEntity>, VoidTransactionRepositoryFactory<TEntity>>();
25+
}
26+
}
27+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using EntityDb.Abstractions.Commands;
2+
using EntityDb.Abstractions.Facts;
3+
using EntityDb.Abstractions.Leases;
4+
using EntityDb.Abstractions.Queries;
5+
using EntityDb.Abstractions.Transactions;
6+
using System;
7+
using System.Diagnostics.CodeAnalysis;
8+
using System.Threading.Tasks;
9+
10+
namespace EntityDb.Void.Transactions
11+
{
12+
internal sealed class VoidTransactionRepository<TEntity> : ITransactionRepository<TEntity>
13+
{
14+
private static readonly Task<Guid[]> _emptyGuidArrayTask = Task.FromResult(Array.Empty<Guid>());
15+
private static readonly Task<object[]> _emptyObjectArrayTask = Task.FromResult(Array.Empty<object>());
16+
private static readonly Task<ICommand<TEntity>[]> _emptyCommandArrayTask = Task.FromResult(Array.Empty<ICommand<TEntity>>());
17+
private static readonly Task<IFact<TEntity>[]> _emptyFactArrayTask = Task.FromResult(Array.Empty<IFact<TEntity>>());
18+
private static readonly Task<ILease[]> _emptyLeaseArrayTask = Task.FromResult(Array.Empty<ILease>());
19+
private static readonly Task<bool> _trueTask = Task.FromResult(true);
20+
21+
public Task<Guid[]> GetTransactionIds(ISourceQuery sourceQuery)
22+
{
23+
return _emptyGuidArrayTask;
24+
}
25+
26+
public Task<Guid[]> GetTransactionIds(ICommandQuery commandQuery)
27+
{
28+
return _emptyGuidArrayTask;
29+
}
30+
31+
public Task<Guid[]> GetTransactionIds(IFactQuery factQuery)
32+
{
33+
return _emptyGuidArrayTask;
34+
}
35+
36+
public Task<Guid[]> GetTransactionIds(ILeaseQuery leaseQuery)
37+
{
38+
return _emptyGuidArrayTask;
39+
}
40+
41+
public Task<Guid[]> GetEntityIds(ISourceQuery sourceQuery)
42+
{
43+
return _emptyGuidArrayTask;
44+
}
45+
46+
public Task<Guid[]> GetEntityIds(ICommandQuery commandQuery)
47+
{
48+
return _emptyGuidArrayTask;
49+
}
50+
51+
public Task<Guid[]> GetEntityIds(IFactQuery factQuery)
52+
{
53+
return _emptyGuidArrayTask;
54+
}
55+
56+
public Task<Guid[]> GetEntityIds(ILeaseQuery leaseQuery)
57+
{
58+
return _emptyGuidArrayTask;
59+
}
60+
61+
public Task<object[]> GetSources(ISourceQuery sourceQuery)
62+
{
63+
return _emptyObjectArrayTask;
64+
}
65+
66+
public Task<ICommand<TEntity>[]> GetCommands(ICommandQuery commandQuery)
67+
{
68+
return _emptyCommandArrayTask;
69+
}
70+
71+
public Task<IFact<TEntity>[]> GetFacts(IFactQuery factQuery)
72+
{
73+
return _emptyFactArrayTask;
74+
}
75+
76+
public Task<ILease[]> GetLeases(ILeaseQuery leaseQuery)
77+
{
78+
return _emptyLeaseArrayTask;
79+
}
80+
81+
public Task<bool> PutTransaction(ITransaction<TEntity> transaction)
82+
{
83+
return _trueTask;
84+
}
85+
86+
[ExcludeFromCodeCoverage]
87+
public void Dispose()
88+
{
89+
}
90+
91+
public ValueTask DisposeAsync()
92+
{
93+
return ValueTask.CompletedTask;
94+
}
95+
}
96+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using EntityDb.Abstractions.Transactions;
2+
using System.Threading.Tasks;
3+
4+
namespace EntityDb.Void.Transactions
5+
{
6+
internal class VoidTransactionRepositoryFactory<TEntity> : ITransactionRepositoryFactory<TEntity>
7+
{
8+
private static readonly Task<ITransactionRepository<TEntity>> _voidTransactionRepositoryTask = Task.FromResult(new VoidTransactionRepository<TEntity>() as ITransactionRepository<TEntity>);
9+
10+
public Task<ITransactionRepository<TEntity>> CreateRepository(ITransactionSessionOptions transactionSessionOptions)
11+
{
12+
return _voidTransactionRepositoryTask;
13+
}
14+
}
15+
}

EntityDb.Void/packages.lock.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": 1,
3+
"dependencies": {
4+
".NETCoreApp,Version=v5.0": {
5+
"entitydb.abstractions": {
6+
"type": "Project"
7+
},
8+
"entitydb.common": {
9+
"type": "Project",
10+
"dependencies": {
11+
"EntityDb.Abstractions": "1.0.0"
12+
}
13+
}
14+
}
15+
}
16+
}

EntityDb.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityDb.Redis.Tests", "Ent
2525
EndProject
2626
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityDb.TestImplementations", "EntityDb.TestImplementations\EntityDb.TestImplementations.csproj", "{E55C33DF-354C-455B-9EA2-FE494D591B45}"
2727
EndProject
28-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityDb.RedisMongoDb.Tests", "EntityDb.RedisMongoDb.Tests\EntityDb.RedisMongoDb.Tests.csproj", "{BD226A77-E572-4FD8-B6C3-335EA4AC6E1F}"
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityDb.RedisMongoDb.Tests", "EntityDb.RedisMongoDb.Tests\EntityDb.RedisMongoDb.Tests.csproj", "{BD226A77-E572-4FD8-B6C3-335EA4AC6E1F}"
29+
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityDb.Void", "EntityDb.Void\EntityDb.Void.csproj", "{C4239113-18BE-4418-87A8-E9617EF0A2DF}"
2931
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -81,6 +83,10 @@ Global
8183
{BD226A77-E572-4FD8-B6C3-335EA4AC6E1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
8284
{BD226A77-E572-4FD8-B6C3-335EA4AC6E1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
8385
{BD226A77-E572-4FD8-B6C3-335EA4AC6E1F}.Release|Any CPU.Build.0 = Release|Any CPU
86+
{C4239113-18BE-4418-87A8-E9617EF0A2DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
87+
{C4239113-18BE-4418-87A8-E9617EF0A2DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
88+
{C4239113-18BE-4418-87A8-E9617EF0A2DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
89+
{C4239113-18BE-4418-87A8-E9617EF0A2DF}.Release|Any CPU.Build.0 = Release|Any CPU
8490
EndGlobalSection
8591
GlobalSection(SolutionProperties) = preSolution
8692
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)