Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a financial oriented example #3

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Qowaiv.DomainModel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qowaiv.DomainModel", "src\Q
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qowaiv.DomainModel.UnitTests", "test\Qowaiv.DomainModel.UnitTests\Qowaiv.DomainModel.UnitTests.csproj", "{EDFE004D-ED15-4A2C-AE63-C17245E87D9D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{14039334-EE87-49C4-88DA-D4526544A51A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{C036985A-F17D-405A-B3FD-37F30FA154FB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{8E1F869D-393B-4F6C-A3C0-1D1D336F9FA8}"
Expand Down Expand Up @@ -53,6 +55,23 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConquerClub.Domain", "example\ConquerClub.Domain\ConquerClub.Domain.csproj", "{51F553DB-472D-4982-9554-A32810CB4026}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConquerClub.UnitTests", "example\ConquerClub.UnitTests\ConquerClub.UnitTests.csproj", "{2B600398-B1B7-4185-BB42-88CEA7CAF69D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qowaiv.Financial.Domain", "example\Qowaiv.Financial.Domain\Qowaiv.Financial.Domain.csproj", "{F50A6FC1-1514-4F56-BCB5-4728AC953349}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qowaiv.Financial.UnitTests", "example\Qowaiv.Financial.UnitTests\Qowaiv.Financial.UnitTests.csproj", "{C8E7405A-3130-415C-9C7A-76EECE2006E5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qowaiv.Financial.Shared", "example\Qowaiv.Financial.Shared\Qowaiv.Financial.Shared.csproj", "{E06AABF6-D6B6-4706-AF75-133C7D061F16}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventStorage.Abstractions", "example\EventStorage.Abstractions\EventStorage.Abstractions\EventStorage.Abstractions.csproj", "{9A3A682A-F0D5-4EC5-A20E-6831D9D41F11}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventStorage.SqlServer", "example\EventStorage.SqlServer\EventStorage.SqlServer.csproj", "{96873D15-FD47-4FCD-AFA1-2F308DEF56E2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventStorage.MongoDb", "example\EventStorage.MongoDb\EventStorage.MongoDb\EventStorage.MongoDb.csproj", "{664AE942-586E-435B-B90E-A3D01658780D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventStorage.EventStoreNet", "example\EventStorage.EventStoreNet\EventStorage.EventStoreNet\EventStorage.EventStoreNet.csproj", "{0CA616C3-C936-4027-9BCB-21EA0DC32240}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventStorage.Local", "example\EventStorage.Local\EventStorage.Local\EventStorage.Local.csproj", "{0885D8C2-B9CB-43AE-8A73-85448918B20C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Qowaiv.Financial.Web", "example\Qowaiv.Financial.Web\Qowaiv.Financial.Web.csproj", "{CDBA33F4-C63E-4D63-8BA1-3383C4E42DF8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -80,6 +99,42 @@ Global
{2B600398-B1B7-4185-BB42-88CEA7CAF69D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B600398-B1B7-4185-BB42-88CEA7CAF69D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B600398-B1B7-4185-BB42-88CEA7CAF69D}.Release|Any CPU.Build.0 = Release|Any CPU
{F50A6FC1-1514-4F56-BCB5-4728AC953349}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F50A6FC1-1514-4F56-BCB5-4728AC953349}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F50A6FC1-1514-4F56-BCB5-4728AC953349}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F50A6FC1-1514-4F56-BCB5-4728AC953349}.Release|Any CPU.Build.0 = Release|Any CPU
{C8E7405A-3130-415C-9C7A-76EECE2006E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8E7405A-3130-415C-9C7A-76EECE2006E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8E7405A-3130-415C-9C7A-76EECE2006E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8E7405A-3130-415C-9C7A-76EECE2006E5}.Release|Any CPU.Build.0 = Release|Any CPU
{E06AABF6-D6B6-4706-AF75-133C7D061F16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E06AABF6-D6B6-4706-AF75-133C7D061F16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E06AABF6-D6B6-4706-AF75-133C7D061F16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E06AABF6-D6B6-4706-AF75-133C7D061F16}.Release|Any CPU.Build.0 = Release|Any CPU
{9A3A682A-F0D5-4EC5-A20E-6831D9D41F11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A3A682A-F0D5-4EC5-A20E-6831D9D41F11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A3A682A-F0D5-4EC5-A20E-6831D9D41F11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A3A682A-F0D5-4EC5-A20E-6831D9D41F11}.Release|Any CPU.Build.0 = Release|Any CPU
{96873D15-FD47-4FCD-AFA1-2F308DEF56E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96873D15-FD47-4FCD-AFA1-2F308DEF56E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96873D15-FD47-4FCD-AFA1-2F308DEF56E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96873D15-FD47-4FCD-AFA1-2F308DEF56E2}.Release|Any CPU.Build.0 = Release|Any CPU
{664AE942-586E-435B-B90E-A3D01658780D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{664AE942-586E-435B-B90E-A3D01658780D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{664AE942-586E-435B-B90E-A3D01658780D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{664AE942-586E-435B-B90E-A3D01658780D}.Release|Any CPU.Build.0 = Release|Any CPU
{0CA616C3-C936-4027-9BCB-21EA0DC32240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CA616C3-C936-4027-9BCB-21EA0DC32240}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CA616C3-C936-4027-9BCB-21EA0DC32240}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CA616C3-C936-4027-9BCB-21EA0DC32240}.Release|Any CPU.Build.0 = Release|Any CPU
{0885D8C2-B9CB-43AE-8A73-85448918B20C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0885D8C2-B9CB-43AE-8A73-85448918B20C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0885D8C2-B9CB-43AE-8A73-85448918B20C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0885D8C2-B9CB-43AE-8A73-85448918B20C}.Release|Any CPU.Build.0 = Release|Any CPU
{CDBA33F4-C63E-4D63-8BA1-3383C4E42DF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDBA33F4-C63E-4D63-8BA1-3383C4E42DF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDBA33F4-C63E-4D63-8BA1-3383C4E42DF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDBA33F4-C63E-4D63-8BA1-3383C4E42DF8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -93,6 +148,15 @@ Global
{E9A5D722-EEAA-4BF5-BD0A-BDECA579275E} = {A4C3C9FF-4EED-41FE-8849-C896429254B5}
{51F553DB-472D-4982-9554-A32810CB4026} = {458A70D6-AEA3-45E8-A789-EB5AB3B1600D}
{2B600398-B1B7-4185-BB42-88CEA7CAF69D} = {458A70D6-AEA3-45E8-A789-EB5AB3B1600D}
{F50A6FC1-1514-4F56-BCB5-4728AC953349} = {14039334-EE87-49C4-88DA-D4526544A51A}
{C8E7405A-3130-415C-9C7A-76EECE2006E5} = {14039334-EE87-49C4-88DA-D4526544A51A}
{E06AABF6-D6B6-4706-AF75-133C7D061F16} = {14039334-EE87-49C4-88DA-D4526544A51A}
{9A3A682A-F0D5-4EC5-A20E-6831D9D41F11} = {14039334-EE87-49C4-88DA-D4526544A51A}
{96873D15-FD47-4FCD-AFA1-2F308DEF56E2} = {14039334-EE87-49C4-88DA-D4526544A51A}
{664AE942-586E-435B-B90E-A3D01658780D} = {14039334-EE87-49C4-88DA-D4526544A51A}
{0CA616C3-C936-4027-9BCB-21EA0DC32240} = {14039334-EE87-49C4-88DA-D4526544A51A}
{0885D8C2-B9CB-43AE-8A73-85448918B20C} = {14039334-EE87-49C4-88DA-D4526544A51A}
{CDBA33F4-C63E-4D63-8BA1-3383C4E42DF8} = {14039334-EE87-49C4-88DA-D4526544A51A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9B55A336-E2D3-4656-9840-D519B3E1159B}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Runtime.Serialization;

namespace EventStorage.Abstractions
{
/// <summary>Exception thrown when no events could be found for the specified aggregate.</summary>
[Serializable]
public class AggregateNotFoundException : Exception
{
/// <summary>Creates a new instance of the <see cref="AggregateNotFoundException"/> object.</summary>
public AggregateNotFoundException()
: this("No Aggregate could be found.") { }

/// <summary>Creates a new instance of the <see cref="AggregateNotFoundException"/> object.</summary>
public AggregateNotFoundException(string message) : base(message) { }

/// <summary>Creates a new instance of the <see cref="AggregateNotFoundException"/> object.</summary>
public AggregateNotFoundException(string message, Exception innerException) : base(message, innerException) { }

/// <summary>Creates a new instance of the <see cref="AggregateNotFoundException"/> object.</summary>
protected AggregateNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
AggregateId = info?.GetString(nameof(AggregateId));
}

/// <inheritdoc/>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info?.AddValue(nameof(AggregateId), AggregateId);
}

/// <summary>The identifier that could not be found.</summary>
public string AggregateId { get; private set; }

/// <summary>Creates a new instance of the <see cref="AggregateNotFoundException"/> object for the specfied identifier.</summary>
/// <typeparam name="TId">
/// The type of th identifier.
/// </typeparam>
/// <param name="id">
/// The identifier of aggregate that could not be found.
/// </param>
public static AggregateNotFoundException ForId<TId>(TId id) => new AggregateNotFoundException($"No Aggregate could be found with id '{id}'.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Runtime.Serialization;

namespace EventStorage.Abstractions
{
/// <summary>Exception thrown when the expected version and the actual version in the storage are different.</summary>
[Serializable]
public class ConcurrencyException : Exception
{
/// <summary>Creates a new instance of the <see cref="ConcurrencyException"/> object.</summary>
public ConcurrencyException(int expectedVersion, int actualVersion)
: this($"A concurrency violation is encountered. Expected version {expectedVersion} but got {actualVersion}.") { }

/// <summary>Creates a new instance of the <see cref="ConcurrencyException"/> object.</summary>
public ConcurrencyException() : this("A concurrency violation is encountered.") { }

/// <summary>Creates a new instance of the <see cref="ConcurrencyException"/> object.</summary>
public ConcurrencyException(string message) : base(message) { }

/// <summary>Creates a new instance of the <see cref="ConcurrencyException"/> object.</summary>
public ConcurrencyException(string message, Exception innerException) : base(message, innerException) { }

/// <summary>Creates a new instance of the <see cref="ConcurrencyException"/> object.</summary>
protected ConcurrencyException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Qowaiv.DomainModel\Qowaiv.DomainModel.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Qowaiv.DomainModel;
using System;
using System.Threading.Tasks;

namespace EventStorage.Abstractions
{
/// <summary>An interface for loading and saving events from and to an <see cref="EventBuffer{TId}"/>.</summary>
/// <typeparam name="TId">
/// The type of the identifier of the event based aggregate (root).
/// </typeparam>
public interface IEventStore<TId>
{
/// <summary>Gets the current version of an aggregate.</summary>
/// <param name="aggregateId">
/// The identifier of the aggregate (root).
/// </param>
Task<int> GetCurrentVersionAsync(TId aggregateId);

/// <summary>Loads events of the specified aggregate root.</summary>
/// <param name="aggregateId">
/// The identity of the aggregate (root).
/// </param>
Task<EventBuffer<TId>> LoadAsync(TId aggregateId) => LoadAsync(aggregateId, 1);

/// <summary>Loads events of the specified aggregate root.</summary>
/// <param name="aggregateId">
/// The identity of the aggregate (root).
/// </param>
/// <param name="firstEvent">
/// The version of the first event to include in the buffer.
/// </param>
Task<EventBuffer<TId>> LoadAsync(TId aggregateId, int firstEvent);

/// <summary>Saves the uncommitted events of the <see cref="EventBuffer{TId}"/>.</summary>
/// <param name="buffer">
/// The <see cref="EventBuffer{TId}"/>.
/// </param>
Task SaveAsync(EventBuffer<TId> buffer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

namespace EventStorage.Abstractions
{
/// <summary>Registers a <see cref="Type"/>/<see cref="string"/> mapping.</summary>
public sealed class TypeMap : IEnumerable<KeyValuePair<Type, string>>
{
private readonly Dictionary<string, Type> _types = new Dictionary<string, Type>();
private readonly Dictionary<Type, string> _names = new Dictionary<Type, string>();

/// <summary>Gets the total of registered <see cref="Type"/> type name combinations.</summary>
public int Count => _types.Count;

/// <summary>Adds all <see cref="Type"/>s of the assembly.</summary>
public TypeMap Add([NotNull]Assembly assembly)
{
return AddRange(assembly.GetTypes());
}

/// <summary>Adds a <see cref="Type"/> and its name.</summary>
public TypeMap Add([NotNull]Type type, [NotNull]string name)
{
lock (locker)
{
var newName = !_names.ContainsKey(type);
var newType = !_types.ContainsKey(name);

if (newName ^ newType)
{
throw new ArgumentException($"The type {type} and/or the name '{name}' has already been added as another pair.");
}
if (newName /* && newType */)
{
_names[type] = name;
_types[name] = type;
}
}
return this;
}

/// <summary>Adds a <see cref="Type"/> and its <see cref="Type.FullName"/>.</summary>
public TypeMap Add(Type type) => Add(type, type?.FullName);

/// <summary>Adds a range of types.</summary>
public TypeMap AddRange([NotNull]params Type[] types)
{
foreach (var type in types.Where(t => !t.IsAbstract && t.IsPublic))
{
Add(type);
}
return this;
}

/// <summary>Tries to get the name of a type.</summary>
public string TryGetName(Type type)
{
if (type is null)
{
return null;
}
_names.TryGetValue(type, out string name);
return name ?? type.FullName;
}

/// <summary>Tries to get a type based on its name.</summary>
public Type TryGetType(string name)
{
if (string.IsNullOrEmpty(name))
{
return null;
}
_types.TryGetValue(name, out Type type);
return type ?? Type.GetType(name, throwOnError: false);
}

/// <inheritdoc />
public IEnumerator<KeyValuePair<Type, string>> GetEnumerator() => _names.GetEnumerator();

/// <inheritdoc />
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

private readonly object locker = new object();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EventStore.Client" Version="21.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\EventStorage.Abstractions\EventStorage.Abstractions\EventStorage.Abstractions.csproj" />
</ItemGroup>

</Project>
Loading