Skip to content

Commit

Permalink
Use CommunityToolkit Aspire EventStore packages
Browse files Browse the repository at this point in the history
  • Loading branch information
fredimachado committed Nov 30, 2024
1 parent cb1e404 commit f7c2fe8
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 159 deletions.
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<PackageVersion Include="Aspirant.Hosting" Version="0.0.3" />
<PackageVersion Include="Aspire.Hosting" Version="9.0.0" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageVersion Include="CommunityToolkit.Aspire.EventStore" Version="9.0.1-beta.92" />
<PackageVersion Include="CommunityToolkit.Aspire.Hosting.EventStore" Version="9.0.1-beta.90" />
<PackageVersion Include="Aspire.Hosting.RabbitMQ" Version="9.0.0" />
<PackageVersion Include="Aspire.RabbitMQ.Client" Version="9.0.0" />
<PackageVersion Include="AspNetCore.HealthChecks.EventStore.gRPC" Version="6.0.1" />
Expand All @@ -26,7 +28,6 @@
<PackageVersion Include="Ardalis.GuardClauses" Version="5.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="EventStore.Client.Grpc.Streams" Version="21.2.0" />
<PackageVersion Include="FakeItEasy" Version="8.3.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.34.1" />
Expand Down
7 changes: 0 additions & 7 deletions NCafe.sln
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NCafe.ServiceDefaults", "sr
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Aspire", "Aspire", "{81ABD551-6547-47EF-8F01-160466F018D2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.EventStore", "src\Aspire\Aspire.Hosting.EventStore\Aspire.Hosting.EventStore.csproj", "{1F5E7F20-3972-4E73-86A9-83F20F6EE8C7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NCafe.Cashier.Api.Tests", "src\Cashier\NCafe.Cashier.Api.Tests\NCafe.Cashier.Api.Tests.csproj", "{BFBE126A-F7B7-4DFC-A4AF-962AD53A22C3}"
EndProject
Global
Expand Down Expand Up @@ -159,10 +157,6 @@ Global
{A7B56906-8702-48CD-9CB0-2274802E54B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7B56906-8702-48CD-9CB0-2274802E54B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7B56906-8702-48CD-9CB0-2274802E54B2}.Release|Any CPU.Build.0 = Release|Any CPU
{1F5E7F20-3972-4E73-86A9-83F20F6EE8C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F5E7F20-3972-4E73-86A9-83F20F6EE8C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F5E7F20-3972-4E73-86A9-83F20F6EE8C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F5E7F20-3972-4E73-86A9-83F20F6EE8C7}.Release|Any CPU.Build.0 = Release|Any CPU
{BFBE126A-F7B7-4DFC-A4AF-962AD53A22C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFBE126A-F7B7-4DFC-A4AF-962AD53A22C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFBE126A-F7B7-4DFC-A4AF-962AD53A22C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -194,7 +188,6 @@ Global
{0203B146-09CB-4350-8375-9759F132BDC2} = {49528FFA-842E-4853-9B8F-77BCE9970D11}
{ED16805D-2DEA-4F88-8BCD-E3460AE89CAF} = {81ABD551-6547-47EF-8F01-160466F018D2}
{A7B56906-8702-48CD-9CB0-2274802E54B2} = {81ABD551-6547-47EF-8F01-160466F018D2}
{1F5E7F20-3972-4E73-86A9-83F20F6EE8C7} = {81ABD551-6547-47EF-8F01-160466F018D2}
{BFBE126A-F7B7-4DFC-A4AF-962AD53A22C3} = {A45EA559-97E3-4460-A2E5-F385D0476851}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
17 changes: 17 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="CommunityToolkit-MainLatest" value="https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-MainLatest/nuget/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="CommunityToolkit-MainLatest">
<package pattern="CommunityToolkit.Aspire.Hosting.EventStore" />
<package pattern="CommunityToolkit.Aspire.EventStore" />
</packageSource>
<packageSource key="nuget">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
1 change: 1 addition & 0 deletions src/Admin/NCafe.Admin.Api/NCafe.Admin.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>ec97a454-f07d-4a4e-8734-91dea638b241</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/NCafe.Admin.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
builder.AddServiceDefaults();

// Add services to the container.
builder.Services.AddEventStoreRepository(builder.Configuration)
.AddEventStoreProjectionService<Product>(builder.Configuration)
builder.AddEventStore("eventstore");
builder.Services.AddEventStoreProjectionService<Product>(builder.Configuration)
.AddInMemoryReadModelRepository<Product>()
.AddHostedService<ProductProjectionService>();

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions src/Aspire/Aspire.Hosting.EventStore/EventStoreResource.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Aspire/NCafe.AppHost/NCafe.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="CommunityToolkit.Aspire.Hosting.EventStore" />
<PackageReference Include="Aspire.Hosting.RabbitMQ" />
</ItemGroup>

Expand All @@ -20,7 +21,6 @@
<ProjectReference Include="..\..\Barista\NCafe.Barista.Api\NCafe.Barista.Api.csproj" />
<ProjectReference Include="..\..\Cashier\NCafe.Cashier.Api\NCafe.Cashier.Api.csproj" />
<ProjectReference Include="..\..\UI\NCafe.Web\NCafe.Web.csproj" />
<ProjectReference Include="..\Aspire.Hosting.EventStore\Aspire.Hosting.EventStore.csproj" IsAspireProjectResource="false" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/Aspire/NCafe.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var builder = DistributedApplication.CreateBuilder(args);

var eventStore = builder.AddEventStore("eventstore")
.WithDataVolume();
.WithDataVolume()
.WithEnvironment("EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP", "true"); // https://github.com/EventStore/EventStore/issues/2640

var rabbitMq = builder.AddRabbitMQ("rabbitmq")
.WithDataVolume()
Expand Down
1 change: 1 addition & 0 deletions src/Barista/NCafe.Barista.Api/NCafe.Barista.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>2d516a09-8eac-4a83-ae3b-bc124cc2e20e</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Barista/NCafe.Barista.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
});

// Add services to the container.
builder.Services.AddEventStoreRepository(builder.Configuration)
.AddEventStoreProjectionService<BaristaOrder>(builder.Configuration)
builder.AddEventStore("eventstore");
builder.Services.AddEventStoreProjectionService<BaristaOrder>(builder.Configuration)
.AddInMemoryReadModelRepository<BaristaOrder>()
.AddHostedService<BaristaOrderProjectionService>();

Expand Down
1 change: 1 addition & 0 deletions src/Cashier/NCafe.Cashier.Api/NCafe.Cashier.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>524b37d5-722b-4196-bcb9-5f33ceb92960</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Cashier/NCafe.Cashier.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
builder.AddRabbitMQClient("rabbitmq");

// Add services to the container.
builder.Services.AddEventStoreRepository(builder.Configuration)
.AddEventStoreProjectionService<Product>(builder.Configuration)
builder.AddEventStore("eventstore");
builder.Services.AddEventStoreProjectionService<Product>(builder.Configuration)
.AddInMemoryReadModelRepository<Product>()
.AddHostedService<ProductProjectionService>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using MediatR;
using NCafe.Cashier.Domain.Entities;
using NCafe.Cashier.Domain.Exceptions;
using NCafe.Cashier.Domain.ReadModels;
using NCafe.Cashier.Domain.ValueObjects;
using NCafe.Core.ReadModels;
using NCafe.Core.Repositories;

namespace NCafe.Cashier.Domain.Commands;
Expand Down
1 change: 0 additions & 1 deletion src/Cashier/NCafe.Cashier.Domain/ValueObjects/OrderItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Ardalis.GuardClauses;
using NCafe.Cashier.Domain.Exceptions;

namespace NCafe.Cashier.Domain.ValueObjects;

Expand Down
18 changes: 6 additions & 12 deletions src/Common/NCafe.Infrastructure/DependencyRegistration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using EventStore.Client;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using NCafe.Core.MessageBus;
using NCafe.Core.Projections;
Expand All @@ -28,18 +28,12 @@ public static IServiceCollection AddMediatR<T>(this IServiceCollection services)
return services;
}

public static IServiceCollection AddEventStoreRepository(this IServiceCollection services, IConfiguration configuration)
public static IHostApplicationBuilder AddEventStore(this IHostApplicationBuilder builder, string connectionName)
{
services.AddSingleton(e =>
{
var settings = EventStoreClientSettings.Create(configuration.GetConnectionString("EventStore"));
var client = new EventStoreClient(settings);
return client;
});
builder.AddEventStoreClient(connectionName);
builder.Services.AddTransient<IRepository, EventStoreRepository>();

services.AddTransient<IRepository, EventStoreRepository>();

return services;
return builder;
}

public static IServiceCollection AddEventStoreProjectionService<TModel>(this IServiceCollection services, IConfiguration configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public async Task Start(CancellationToken cancellationToken)

_logger.LogInformation("Subscribing to EventStore Stream '{EventStoreStream}'.", streamName);

// TODO: Add support for checkpointing or use persistent subscription.
await _eventStoreClient.SubscribeToStreamAsync(
streamName,
FromStream.Start,
EventAppeared,
resolveLinkTos: true,
SubscriptionDropped,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="Aspire.RabbitMQ.Client" />
<PackageReference Include="EventStore.Client.Grpc.Streams" />
<PackageReference Include="CommunityToolkit.Aspire.EventStore" />
<PackageReference Include="MediatR" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
<PackageReference Include="Newtonsoft.Json" />
Expand Down

0 comments on commit f7c2fe8

Please sign in to comment.