Skip to content

Commit

Permalink
chore: Update project references and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
foxminchan committed Aug 25, 2024
1 parent 2ecc149 commit 833328b
Show file tree
Hide file tree
Showing 59 changed files with 326 additions and 143 deletions.
7 changes: 7 additions & 0 deletions BookWorm.sln
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookWorm.MailDev.Hosting",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookWorm.Gateway", "src\BookWorm.Gateway\BookWorm.Gateway.csproj", "{9AE80189-4D7D-44F0-84C8-127DA27D7AC8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookWorm.Constants", "src\BookWorm.Constants\BookWorm.Constants.csproj", "{C7663D58-F93F-466E-8A93-A6E30396C6B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -162,6 +164,10 @@ Global
{9AE80189-4D7D-44F0-84C8-127DA27D7AC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AE80189-4D7D-44F0-84C8-127DA27D7AC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AE80189-4D7D-44F0-84C8-127DA27D7AC8}.Release|Any CPU.Build.0 = Release|Any CPU
{C7663D58-F93F-466E-8A93-A6E30396C6B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7663D58-F93F-466E-8A93-A6E30396C6B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7663D58-F93F-466E-8A93-A6E30396C6B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7663D58-F93F-466E-8A93-A6E30396C6B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -194,6 +200,7 @@ Global
{D1719092-035E-4E02-ACEC-782107CFE51C} = {1A0E0FD4-396E-4DBA-B3F1-ED4ACCE50D1B}
{0C0E5158-F59D-45E0-A6C5-63198A3D0492} = {1A0E0FD4-396E-4DBA-B3F1-ED4ACCE50D1B}
{9AE80189-4D7D-44F0-84C8-127DA27D7AC8} = {C50229F2-978B-4961-8865-83767C55E8FB}
{C7663D58-F93F-466E-8A93-A6E30396C6B6} = {5E13A8D9-B0C4-4388-A99D-AEF14B63CA8C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {233A9FBF-DCD1-40C1-A6A5-9D37C92557BB}
Expand Down
1 change: 1 addition & 0 deletions src/BookWorm.AppHost/BookWorm.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BookWorm.Constants\BookWorm.Constants.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\BookWorm.HealthCheck.Hosting\BookWorm.HealthCheck.Hosting.csproj"
IsAspireProjectResource="false" />
<ProjectReference Include="..\BookWorm.MailDev.Hosting\BookWorm.MailDev.Hosting.csproj"
Expand Down
1 change: 1 addition & 0 deletions src/BookWorm.AppHost/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
global using Aspirant.Hosting;
global using Aspire.Hosting.Lifecycle;
global using BookWorm.AppHost;
global using BookWorm.Constants;
global using BookWorm.HealthCheck.Hosting;
global using BookWorm.MailDev.Hosting;
global using Microsoft.Extensions.Hosting;
Expand Down
24 changes: 11 additions & 13 deletions src/BookWorm.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,32 @@
.WithMongoExpress()
.WithDataBindMount("../../mnt/mongodb");

var redis = builder.AddRedis("redis", 6379)
var redis = builder.AddRedis(ServiceName.Redis, 6379)
.WithRedisCommander()
.WithDataBindMount("../../mnt/redis");

var catalogDb = postgres.AddDatabase("catalogdb");
var orderingDb = postgres.AddDatabase("orderingdb");
var identityDb = postgres.AddDatabase("identitydb");
var notificationDb = postgres.AddDatabase("notificationdb");
var ratingDb = mongodb.AddDatabase("ratingdb");
var catalogDb = postgres.AddDatabase(ServiceName.Database.Catalog);
var orderingDb = postgres.AddDatabase(ServiceName.Database.Ordering);
var identityDb = postgres.AddDatabase(ServiceName.Database.Identity);
var notificationDb = postgres.AddDatabase(ServiceName.Database.Notification);
var ratingDb = mongodb.AddDatabase(ServiceName.Database.Rating);

var storage = builder.AddAzureStorage("storage");

if (builder.Environment.IsDevelopment())
{
storage.RunAsEmulator(
config => config.WithDataBindMount("../../mnt/azurite"));
storage.RunAsEmulator(config => config.WithDataBindMount("../../mnt/azurite"));
}

var blobs = storage.AddBlobs("blobs");
var blobs = storage.AddBlobs(ServiceName.Blob);

var openAi = builder.AddConnectionString("openai");
var openAi = builder.AddConnectionString(ServiceName.OpenAi);

var rabbitMq = builder
.AddRabbitMQ("eventbus")
.AddRabbitMQ(ServiceName.EventBus)
.WithManagementPlugin();

var smtpServer = builder.AddMailDev("mailserver", 1080);
var smtpServer = builder.AddMailDev(ServiceName.Mail, 1080);

// Services
var identityApi = builder.AddProject<BookWorm_Identity>("identity-api")
Expand All @@ -57,7 +56,6 @@
var identityEndpoint = identityApi.GetEndpoint(launchProfileName);

var catalogApi = builder.AddProject<BookWorm_Catalog>("catalog-api")
.WithReference(blobs)
.WithReference(rabbitMq)
.WithReference(catalogDb)
.WithReference(redis)
Expand Down
1 change: 1 addition & 0 deletions src/BookWorm.Basket/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
global using Ardalis.Result;
global using BookWorm.Basket.Grpc;
global using BookWorm.Basket.Infrastructure.Redis;
global using BookWorm.Constants;
global using BookWorm.Core.SeedWork;
global using BookWorm.Core.SharedKernel;
global using BookWorm.ServiceDefaults;
Expand Down
2 changes: 1 addition & 1 deletion src/BookWorm.Basket/Infrastructure/Redis/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ internal static class Extension
{
public static IHostApplicationBuilder AddRedisCache(this IHostApplicationBuilder builder)
{
builder.AddRedisClient("redis");
builder.AddRedisClient(ServiceName.Redis);

builder.Services.AddSingleton<IRedisService, RedisService>();

Expand Down
4 changes: 2 additions & 2 deletions src/BookWorm.Basket/Infrastructure/Redis/RedisService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ public sealed class RedisService(IConfiguration configuration) : IRedisService
private readonly SemaphoreSlim _connectionLock = new(1, 1);

private readonly Lazy<ConnectionMultiplexer> _connectionMultiplexer = new(() =>
ConnectionMultiplexer.Connect(
configuration.GetConnectionString("redis") ?? throw new InvalidOperationException()));
ConnectionMultiplexer.Connect(configuration.GetConnectionString(ServiceName.Redis) ??
throw new InvalidOperationException()));

private ConnectionMultiplexer ConnectionMultiplexer => _connectionMultiplexer.Value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ namespace BookWorm.Basket.IntegrationEvents.EventHandlers;

public sealed class OrderCreatedIntegrationEventHandler(
IRedisService redisService,
ILogger<OrderCreatedIntegrationEventHandler> logger,
IPublishEndpoint publishEndpoint) : IConsumer<OrderCreatedIntegrationEvent>
{
public async Task Consume(ConsumeContext<OrderCreatedIntegrationEvent> context)
{
var @event = context.Message;

logger.LogInformation("[{Consumer}] - Removing basket for order {OrderId}",
nameof(OrderCreatedIntegrationEventHandler),
@event.OrderId);

var basketId = context.Message.BasketId.ToString();
var basket = await redisService.HashGetAsync<Domain.Basket?>(nameof(Basket), basketId);

if (basket is null)
{
await PublishBasketCheckoutFailed(context.Message.OrderId);
await PublishBasketCheckoutFailed(@event.OrderId);
return;
}

Expand All @@ -23,7 +30,7 @@ public async Task Consume(ConsumeContext<OrderCreatedIntegrationEvent> context)
}
catch (Exception)
{
await PublishBasketCheckoutFailed(context.Message.OrderId);
await PublishBasketCheckoutFailed(@event.OrderId);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/BookWorm.Catalog/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ internal static class Extensions
{
public static void AddApplicationServices(this IHostApplicationBuilder builder)
{
builder.AddRedisOutputCache("cache");
builder.AddRedisOutputCache(ServiceName.Redis);

builder.Services.AddGrpc();

Expand Down
4 changes: 2 additions & 2 deletions src/BookWorm.Catalog/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global using System.Diagnostics.CodeAnalysis;
global using System.Diagnostics.CodeAnalysis;
global using System.Text.Json.Serialization;
global using Ardalis.GuardClauses;
global using Ardalis.Result;
Expand All @@ -11,7 +11,6 @@
global using BookWorm.ServiceDefaults;
global using BookWorm.Shared.ActivityScope;
global using BookWorm.Shared.Bus;
global using BookWorm.Shared.Constants;
global using BookWorm.Shared.Converters;
global using BookWorm.Shared.Endpoints;
global using BookWorm.Shared.Exceptions;
Expand All @@ -33,5 +32,6 @@
global using Azure;
global using Azure.Storage.Blobs;
global using Azure.Storage.Blobs.Models;
global using BookWorm.Constants;
global using Polly;
global using Polly.Registry;
2 changes: 1 addition & 1 deletion src/BookWorm.Catalog/Infrastructure/Ai/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static IHostApplicationBuilder AddAi(this IHostApplicationBuilder builder
{
var modelName = builder.Configuration["AiOptions:OpenAi:EmbeddingName"] ?? "text-embedding-3-small";

builder.AddAzureOpenAIClient("openai");
builder.AddAzureOpenAIClient(ServiceName.OpenAi);
builder.Services.AddOpenAITextEmbeddingGeneration(modelName);

builder.Services.AddSingleton<IAiService, AiService>();
Expand Down
2 changes: 1 addition & 1 deletion src/BookWorm.Catalog/Infrastructure/Blob/AzuriteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public sealed class AzuriteService(ResiliencePipelineProvider<string> pipeline, IConfiguration configuration)
: IAzuriteService
{
private readonly BlobContainerClient _container = new(configuration.GetConnectionString("blobs"),
private readonly BlobContainerClient _container = new(configuration.GetConnectionString(ServiceName.Blob),
nameof(Catalog));

private readonly ResiliencePipeline _policy = pipeline.GetPipeline(nameof(Blob));
Expand Down
2 changes: 1 addition & 1 deletion src/BookWorm.Catalog/Infrastructure/Data/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static IHostApplicationBuilder AddPersistence(this IHostApplicationBuilde
{
builder.Services.AddMigration<CatalogContext>();

builder.AddNpgsqlDbContext<CatalogContext>("catalogdb", configureDbContextOptions:
builder.AddNpgsqlDbContext<CatalogContext>(ServiceName.Database.Catalog, configureDbContextOptions:
dbContextOptionsBuilder =>
{
dbContextOptionsBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ namespace BookWorm.Catalog.IntegrationEvents.EventHandlers;

public sealed class FeedbackCreatedIntegrationEventHandler(
IRepository<Book> repository,
ILogger<FeedbackCreatedIntegrationEventHandler> logger,
IPublishEndpoint publishEndpoint) : IConsumer<FeedbackCreatedIntegrationEvent>
{
public async Task Consume(ConsumeContext<FeedbackCreatedIntegrationEvent> context)
{
var @event = context.Message;

logger.LogInformation("[{Consumer}] - Adding rating {Rating} to book {BookId}",
nameof(FeedbackCreatedIntegrationEventHandler),
@event.Rating,
@event.BookId);

var book = await repository.GetByIdAsync(@event.BookId);

if (book is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

namespace BookWorm.Catalog.IntegrationEvents.EventHandlers;

internal sealed class FeedbackDeletedIntegrationEventHandler(IRepository<Book> repository)
: IConsumer<FeedbackDeletedIntegrationEvent>
internal sealed class FeedbackDeletedIntegrationEventHandler(
IRepository<Book> repository,
ILogger<FeedbackDeletedIntegrationEventHandler> logger) : IConsumer<FeedbackDeletedIntegrationEvent>
{
public async Task Consume(ConsumeContext<FeedbackDeletedIntegrationEvent> context)
{
var @event = context.Message;

logger.LogInformation("[{Consumer}] - Removing rating {Rating} from book {BookId}",
nameof(FeedbackDeletedIntegrationEventHandler),
@event.Rating,
@event.BookId);

var book = await repository.GetByIdAsync(@event.BookId);

if (book is null)
Expand Down
1 change: 1 addition & 0 deletions src/BookWorm.Constants/BookWorm.Constants.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Project Sdk="Microsoft.NET.Sdk" />
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BookWorm.Shared.Constants;
namespace BookWorm.Constants;

public static class DataSchemaLength
{
Expand Down
23 changes: 23 additions & 0 deletions src/BookWorm.Constants/ServiceName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace BookWorm.Constants;

public static class ServiceName
{
public const string EventBus = "eventbus";

public const string Redis = "redis";

public const string OpenAi = "openai";

public const string Blob = "blob";

public const string Mail = "mailserver";

public static class Database
{
public const string Catalog = "catalogdb";
public const string Ordering = "orderingdb";
public const string Identity = "identitydb";
public const string Notification = "notificationdb";
public const string Rating = "ratingdb";
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BookWorm.Shared.Constants;
namespace BookWorm.Constants;

public static class UniqueType
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BookWorm.Shared.Constants;
namespace BookWorm.Constants;

public static class VectorType
{
Expand Down
2 changes: 1 addition & 1 deletion src/BookWorm.Identity/DataProtection/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class Extension
{
public static IHostApplicationBuilder AddRedisDataProtection(this IHostApplicationBuilder builder)
{
var conn = builder.Configuration.GetConnectionString("redis");
var conn = builder.Configuration.GetConnectionString(ServiceName.Redis);

if (string.IsNullOrWhiteSpace(conn))
{
Expand Down
1 change: 1 addition & 0 deletions src/BookWorm.Identity/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
global using Duende.IdentityServer.Models;
global using Microsoft.EntityFrameworkCore;
global using System.Diagnostics;
global using BookWorm.Constants;
global using BookWorm.Identity.Data;
global using BookWorm.Identity.Data.CompliedModels;
global using BookWorm.Identity.DataProtection;
Expand Down
2 changes: 1 addition & 1 deletion src/BookWorm.Identity/HostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde

builder.Services.AddMigration<ApplicationDbContext, SeedData>();

builder.AddNpgsqlDbContext<ApplicationDbContext>("identitydb",
builder.AddNpgsqlDbContext<ApplicationDbContext>(ServiceName.Database.Identity,
configureDbContextOptions: dbContextOptionsBuilder => dbContextOptionsBuilder.UseNpgsql()
.UseModel(ApplicationDbContextModel.Instance));

Expand Down
4 changes: 0 additions & 4 deletions src/BookWorm.Identity/Options/ServiceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@ public sealed class ServiceOptions
public string Basket { get; set; } = string.Empty;

public string Rating { get; set; } = string.Empty;

public string StoreFront { get; set; } = string.Empty;

public string BackOffice { get; set; } = string.Empty;
}
17 changes: 12 additions & 5 deletions src/BookWorm.Notification/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace BookWorm.Notification.Extensions;
using BookWorm.Constants;
using BookWorm.Notification.OpenTelemetry;

namespace BookWorm.Notification.Extensions;

internal static class Extensions
{
Expand All @@ -9,7 +12,7 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)

builder.AddRabbitMqEventBus(typeof(Program));

var emailConn = new UriBuilder(builder.Configuration.GetConnectionString("mailserver") ??
var emailConn = new UriBuilder(builder.Configuration.GetConnectionString(ServiceName.Mail) ??
throw new InvalidOperationException());

var defaultFromEmail = builder.Configuration["Smtp:Email"];
Expand All @@ -28,14 +31,18 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)
.AddTimeout(TimeSpan.FromSeconds(10)));

builder.Services.AddOpenTelemetry()
.WithMetrics(t => t.AddMeter("Smtp"))
.WithTracing(t => t.AddSource("Smtp"));
.WithMetrics(t => t
.AddMeter(SmtpTelemetry.ActivityName)
.AddMeter(MartenTelemetry.ActivityName))
.WithTracing(t => t
.AddSource(SmtpTelemetry.ActivityName)
.AddSource(MartenTelemetry.ActivityName));

builder.Services.AddMarten(_ =>
{
var options = new StoreOptions();
var dbConn = builder.Configuration.GetConnectionString("notificationdb");
var dbConn = builder.Configuration.GetConnectionString(ServiceName.Database.Notification);
Guard.Against.NullOrEmpty(dbConn);
options.Connection(dbConn);
Expand Down
12 changes: 12 additions & 0 deletions src/BookWorm.Notification/Extensions/NotificationTrace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace BookWorm.Notification.Extensions;

internal static partial class NotificationTrace
{
[LoggerMessage(EventId = 0, Level = LogLevel.Information,
Message = "[{Service}] Sending email to {To} with subject {Subject}")]
public static partial void LogEmailSending(ILogger logger, string? service, string? to, string? subject);

[LoggerMessage(EventId = 1, Level = LogLevel.Error,
Message = "[{Service}] Failed to process email to {To} with error: {Error}")]
public static partial void LogEmailFailed(ILogger logger, string? service, string? to, string? error);
}
Loading

0 comments on commit 833328b

Please sign in to comment.