Skip to content

Commit 3704526

Browse files
committed
Took out Core code to separate project in Simple EventStoreDB
Got rid of the reference to Core projects
1 parent 351bca8 commit 3704526

35 files changed

+277
-76
lines changed

EventSourcing.NetCore.sln

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,17 @@ EndProject
203203
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marten.Integration.Tests", "Marten.Integration.Tests\Marten.Integration.Tests.csproj", "{D9D67A6C-FE95-4864-B8F1-BD2689134590}"
204204
EndProject
205205
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Api.Testing", "Core.Api.Testing\Core.Api.Testing.csproj", "{825A40DB-5AB5-4565-AADB-28AC760D0A43}"
206-
EndProjectProject("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simple", "Simple", "{11DD4963-5BB4-4E1B-9475-8EB10C822BFC}"
206+
EndProject
207+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Simple", "Simple", "{11DD4963-5BB4-4E1B-9475-8EB10C822BFC}"
207208
EndProject
208209
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ECommerce.Api", "Sample\EventStoreDB\Simple\ECommerce.Api\ECommerce.Api.csproj", "{414D1D34-1002-4159-B738-DF3EE042F9FD}"
209210
EndProject
210211
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ECommerce", "Sample\EventStoreDB\Simple\ECommerce\ECommerce.csproj", "{C8CBBED5-8999-4643-96E6-E56B3A940F97}"
211212
EndProject
212213
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ECommerce.Api.Tests", "Sample\EventStoreDB\Simple\ECommerce.Api.Tests\ECommerce.Api.Tests.csproj", "{36C7CF36-254A-48D5-8181-9196DB1A034B}"
213214
EndProject
215+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Api.Testing", "Core.Api.Testing\Core.Api.Testing.csproj", "{5258F44A-9B51-4F7F-BBB8-D4C81A921C4F}"
216+
EndProject
214217
Global
215218
GlobalSection(SolutionConfigurationPlatforms) = preSolution
216219
Debug|Any CPU = Debug|Any CPU
@@ -481,6 +484,10 @@ Global
481484
{36C7CF36-254A-48D5-8181-9196DB1A034B}.Debug|Any CPU.Build.0 = Debug|Any CPU
482485
{36C7CF36-254A-48D5-8181-9196DB1A034B}.Release|Any CPU.ActiveCfg = Release|Any CPU
483486
{36C7CF36-254A-48D5-8181-9196DB1A034B}.Release|Any CPU.Build.0 = Release|Any CPU
487+
{5258F44A-9B51-4F7F-BBB8-D4C81A921C4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
488+
{5258F44A-9B51-4F7F-BBB8-D4C81A921C4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
489+
{5258F44A-9B51-4F7F-BBB8-D4C81A921C4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
490+
{5258F44A-9B51-4F7F-BBB8-D4C81A921C4F}.Release|Any CPU.Build.0 = Release|Any CPU
484491
EndGlobalSection
485492
GlobalSection(SolutionProperties) = preSolution
486493
HideSolutionNode = FALSE
@@ -568,6 +575,7 @@ Global
568575
{414D1D34-1002-4159-B738-DF3EE042F9FD} = {11DD4963-5BB4-4E1B-9475-8EB10C822BFC}
569576
{C8CBBED5-8999-4643-96E6-E56B3A940F97} = {11DD4963-5BB4-4E1B-9475-8EB10C822BFC}
570577
{36C7CF36-254A-48D5-8181-9196DB1A034B} = {11DD4963-5BB4-4E1B-9475-8EB10C822BFC}
578+
{5258F44A-9B51-4F7F-BBB8-D4C81A921C4F} = {0570E45A-2EB6-4C4C-84E4-2C80E1FECEB5}
571579
EndGlobalSection
572580
GlobalSection(ExtensibilityGlobals) = postSolution
573581
SolutionGuid = {A5F55604-2FF3-43B7-B657-4F18E6E95D3B}

Sample/EventStoreDB/Simple/ECommerce.Api.Tests/ECommerce.Api.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
<PrivateAssets>all</PrivateAssets>
1919
</PackageReference>
2020
</ItemGroup>
21-
21+
2222
<ItemGroup>
2323
<FrameworkReference Include="Microsoft.AspNetCore.App" />
2424
</ItemGroup>
2525

2626
<ItemGroup>
27-
<ProjectReference Include="..\..\..\..\Core.Testing\Core.Testing.csproj" />
27+
<ProjectReference Include="..\..\..\..\Core.Api.Testing\Core.Api.Testing.csproj" />
2828
<ProjectReference Include="..\ECommerce.Api\ECommerce.Api.csproj" />
2929
<ProjectReference Include="..\ECommerce\ECommerce.csproj" />
3030
</ItemGroup>

Sample/EventStoreDB/Simple/ECommerce.Api.Tests/ShoppingCarts/Confirming/ConfirmShoppingCartTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Net;
33
using System.Net.Http;
44
using System.Threading.Tasks;
5-
using Core.Testing;
5+
using Core.Api.Testing;
66
using ECommerce.Api.Requests;
77
using ECommerce.ShoppingCarts;
88
using ECommerce.ShoppingCarts.GettingCartById;
@@ -15,7 +15,7 @@ public class ConfirmShoppingCartFixture: ApiFixture<Startup>
1515
{
1616
protected override string ApiUrl => "/api/ShoppingCarts";
1717

18-
public Guid CartId { get; private set; }
18+
public Guid ShoppingCartId { get; private set; }
1919

2020
public readonly Guid ClientId = Guid.NewGuid();
2121

@@ -26,9 +26,9 @@ public override async Task InitializeAsync()
2626
var initializeResponse = await Post(new InitializeShoppingCartRequest(ClientId));
2727
initializeResponse.EnsureSuccessStatusCode();
2828

29-
CartId = await initializeResponse.GetResultFromJson<Guid>();
29+
ShoppingCartId = await initializeResponse.GetResultFromJson<Guid>();
3030

31-
CommandResponse = await Put($"{CartId}/confirmation");
31+
CommandResponse = await Put($"{ShoppingCartId}/confirmation");
3232
}
3333
}
3434

@@ -56,7 +56,7 @@ public Task Put_Should_Return_OK()
5656
public async Task Put_Should_Confirm_ShoppingCart()
5757
{
5858
// prepare query
59-
var query = $"{fixture.CartId}";
59+
var query = $"{fixture.ShoppingCartId}";
6060

6161
//send query
6262
var queryResponse = await fixture.Get(query, 30,
@@ -66,7 +66,7 @@ public async Task Put_Should_Confirm_ShoppingCart()
6666

6767
var cartDetails = await queryResponse.GetResultFromJson<ShoppingCartDetails>();
6868
cartDetails.Should().NotBeNull();
69-
cartDetails.Id.Should().Be(fixture.CartId);
69+
cartDetails.Id.Should().Be(fixture.ShoppingCartId);
7070
cartDetails.Status.Should().Be(ShoppingCartStatus.Confirmed);
7171
cartDetails.ClientId.Should().Be(fixture.ClientId);
7272
cartDetails.Version.Should().Be(2);

Sample/EventStoreDB/Simple/ECommerce.Api.Tests/ShoppingCarts/Initializing/InitializeShoppingCartTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Net;
33
using System.Net.Http;
44
using System.Threading.Tasks;
5-
using Core.Testing;
5+
using Core.Api.Testing;
66
using ECommerce.Api.Requests;
77
using ECommerce.ShoppingCarts;
88
using ECommerce.ShoppingCarts.GettingCartById;

Sample/EventStoreDB/Simple/ECommerce.Api/Requests/ShoppingCartsRequests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ProductItemRequest
1414
}
1515

1616
public record AddProductRequest(
17-
Guid? CartId,
17+
Guid? ShoppingCartId,
1818
ProductItemRequest? ProductItem
1919
);
2020

@@ -25,7 +25,7 @@ public record PricedProductItemRequest(
2525
);
2626

2727
public record RemoveProductRequest(
28-
Guid? CartId,
28+
Guid? ShoppingCartId,
2929
PricedProductItemRequest? ProductItem
3030
);
3131
}

Sample/EventStoreDB/Simple/ECommerce.Api/Startup.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
using System;
2-
using Core.WebApi.Middlewares.ExceptionHandling;
1+
using Core.WebApi.Middlewares.ExceptionHandling;
32
using ECommerce.Api.Core;
43
using ECommerce.Core;
5-
using ECommerce.Storage;
64
using Microsoft.AspNetCore.Builder;
75
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.EntityFrameworkCore;
96
using Microsoft.Extensions.Configuration;
107
using Microsoft.Extensions.DependencyInjection;
118
using Microsoft.Extensions.Hosting;

Sample/EventStoreDB/Simple/ECommerce/Core/Commands/CommandHandler.cs renamed to Sample/EventStoreDB/Simple/ECommerce.Core/Commands/CommandHandler.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
namespace ECommerce.Core.Commands
88
{
9-
public interface ICommandHandler<in T>
10-
{
11-
ValueTask Handle(T command, CancellationToken token);
12-
}
13-
149
public static class CommandHandlerExtensions
1510
{
1611
public static async Task HandleCreateCommand<TCommand, TEntity>(
@@ -44,29 +39,25 @@ CancellationToken ct
4439
await repository.Append(id, @event, ct);
4540
}
4641

47-
public static IServiceCollection AddCommandHandler<TCommand, TCommandHandler>(this IServiceCollection services)
48-
where TCommandHandler: class, ICommandHandler<TCommand>
49-
=> services
50-
.AddTransient<ICommandHandler<TCommand>, TCommandHandler>()
51-
.AddTransient<Func<TCommand, CancellationToken, ValueTask>>((sp) =>
52-
async (command, ct) =>
53-
{
54-
var commandHandler = sp.GetRequiredService<ICommandHandler<TCommand>>();
55-
await commandHandler.Handle(command, ct);
56-
});
57-
5842
public static IServiceCollection AddCreateCommandHandler<TCommand, TEntity>(
5943
this IServiceCollection services,
6044
Func<TCommand, object> handle,
6145
Func<TCommand, string> getId
46+
) where TEntity : notnull
47+
=> AddCreateCommandHandler<TCommand, TEntity>(services, _ => handle, getId);
48+
49+
public static IServiceCollection AddCreateCommandHandler<TCommand, TEntity>(
50+
this IServiceCollection services,
51+
Func<IServiceProvider, Func<TCommand, object>> handle,
52+
Func<TCommand, string> getId
6253
) where TEntity : notnull
6354
=> services
6455
.AddTransient<Func<TCommand, CancellationToken, ValueTask>>(sp =>
6556
{
6657
var repository = sp.GetRequiredService<IEventStoreDBRepository<TEntity>>();
6758

6859
return async (command, ct) =>
69-
await HandleCreateCommand(repository, handle, getId, command, ct);
60+
await HandleCreateCommand(repository, handle(sp), getId, command, ct);
7061
});
7162

7263

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
12+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
14+
<PackageReference Include="Polly" Version="7.2.2" />
15+
16+
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="21.2.0" />
17+
18+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7" />
19+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.7">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
23+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.7" />
24+
</ItemGroup>
25+
26+
</Project>

0 commit comments

Comments
 (0)