Refactored service bus lifetiemes to singleton

This commit is contained in:
Khwezi Mngoma
2026-05-09 09:03:12 +02:00
parent d998aac7c4
commit 398a8d3827
10 changed files with 31 additions and 13 deletions
@@ -11,7 +11,7 @@
<!-- Nuget Package Details --> <!-- Nuget Package Details -->
<PropertyGroup> <PropertyGroup>
<PackageId>LiteCharms.Abstractions</PackageId> <PackageId>LiteCharms.Abstractions</PackageId>
<Version>1.0.19</Version> <Version>1.0.20</Version>
<Authors>Khwezi Mngoma</Authors> <Authors>Khwezi Mngoma</Authors>
<Company>Lite Charms (PTY) Ltd</Company> <Company>Lite Charms (PTY) Ltd</Company>
<Description>Shared abstractions for Lite Charms applications.</Description> <Description>Shared abstractions for Lite Charms applications.</Description>
@@ -11,7 +11,7 @@
<!-- Nuget Package Details --> <!-- Nuget Package Details -->
<PropertyGroup> <PropertyGroup>
<PackageId>LiteCharms.Entities</PackageId> <PackageId>LiteCharms.Entities</PackageId>
<Version>1.0.19</Version> <Version>1.0.20</Version>
<Authors>Khwezi Mngoma</Authors> <Authors>Khwezi Mngoma</Authors>
<Company>Lite Charms (PTY) Ltd</Company> <Company>Lite Charms (PTY) Ltd</Company>
<Description>Shared entities for Lite Charms applications.</Description> <Description>Shared entities for Lite Charms applications.</Description>
@@ -22,7 +22,7 @@
<!-- Nuget Package Details --> <!-- Nuget Package Details -->
<PropertyGroup> <PropertyGroup>
<PackageId>LiteCharms.Extensions</PackageId> <PackageId>LiteCharms.Extensions</PackageId>
<Version>1.0.19</Version> <Version>1.0.20</Version>
<Authors>Khwezi Mngoma</Authors> <Authors>Khwezi Mngoma</Authors>
<Company>Lite Charms (PTY) Ltd</Company> <Company>Lite Charms (PTY) Ltd</Company>
<Description>Extension components for Lite Charms applications.</Description> <Description>Extension components for Lite Charms applications.</Description>
@@ -49,6 +49,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.7" /> <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.7" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.7" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.7" />
<PackageReference Include="Quartz.AspNetCore" Version="3.18.1" /> <PackageReference Include="Quartz.AspNetCore" Version="3.18.1" />
<PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.18.1" />
<!-- Global Usings --> <!-- Global Usings -->
<Using Include="Microsoft.Extensions.Diagnostics.HealthChecks" /> <Using Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
+1 -1
View File
@@ -17,7 +17,7 @@ public static class Quartz
{ {
config.SchedulerName = schedulerName; config.SchedulerName = schedulerName;
config.SchedulerId = schedulerId; config.SchedulerId = schedulerId;
config.UseSimpleTypeLoader(); config.UseSimpleTypeLoader();
config.UseDefaultThreadPool(options => options.MaxConcurrency = 0); config.UseDefaultThreadPool(options => options.MaxConcurrency = 0);
config.UseTimeZoneConverter(); config.UseTimeZoneConverter();
+6 -5
View File
@@ -1,26 +1,27 @@
using LiteCharms.Abstractions; using LiteCharms.Abstractions;
using LiteCharms.Infrastructure.ServiceBus; using LiteCharms.Infrastructure.ServiceBus;
using LiteCharms.Infrastructure.ServiceBus.Exchanges; using LiteCharms.Infrastructure.ServiceBus.Exchanges;
using LiteCharms.Infrastructure.ServiceBus.Queues;
namespace LiteCharms.Extensions; namespace LiteCharms.Extensions;
public static class ServiceBus public static class ServiceBus
{ {
public static IServiceCollection AddGeneralServiceBus(this IServiceCollection services) => services public static IServiceCollection AddGeneralServiceBus(this IServiceCollection services) => services
.AddTransient<GeneralServiceBus>() .AddSingleton<GeneralQueue>()
.AddHostedService<GeneralExchange>() .AddHostedService<GeneralExchange>()
.AddKeyedTransient<IEventBus, GeneralServiceBus>(Constants.GeneralServiceBus) .AddKeyedSingleton<IEventBus, GeneralServiceBus>(Constants.GeneralServiceBus)
.AddMemoryCache(); .AddMemoryCache();
public static IServiceCollection AddEmailServiceBus(this IServiceCollection services) => services public static IServiceCollection AddEmailServiceBus(this IServiceCollection services) => services
.AddTransient<EmailServiceBus>() .AddSingleton<EmailQueue>()
.AddHostedService<EmailExchange>() .AddHostedService<EmailExchange>()
.AddKeyedTransient<IEventBus, EmailServiceBus>(Constants.EmailServiceBus) .AddKeyedTransient<IEventBus, EmailServiceBus>(Constants.EmailServiceBus)
.AddMemoryCache(); .AddMemoryCache();
public static IServiceCollection AddSalesServiceBus(this IServiceCollection services) => services public static IServiceCollection AddSalesServiceBus(this IServiceCollection services) => services
.AddTransient<SalesServiceBus>() .AddSingleton<SalesQueue>()
.AddHostedService<SalesExchange>() .AddHostedService<SalesExchange>()
.AddKeyedTransient<IEventBus, SalesServiceBus>(Constants.SalesServiceBus) .AddKeyedSingleton<IEventBus, SalesServiceBus>(Constants.SalesServiceBus)
.AddMemoryCache(); .AddMemoryCache();
} }
@@ -0,0 +1,17 @@
{
"payfast-local": {
"baseUrl": "https://localhost:7196",
"paymentId": "jdPB2zaKM3Z",
"signature": "6aeff59bb74f2448ff2c3d81b2ec95de",
"item_name": "System Architecture Book",
"amount": "350.00"
},
"payfast-uat": {
"baseUrl": "https://api.uat.midrandbooks.co.za",
"paymentId": "jdPB2zaKM3Z",
"signature": "6aeff59bb74f2448ff2c3d81b2ec95de",
"item_name": "System Architecture Book",
"amount": "350.00"
}
}
@@ -11,7 +11,7 @@
<!-- Nuget Package Details --> <!-- Nuget Package Details -->
<PropertyGroup> <PropertyGroup>
<PackageId>LiteCharms.Features</PackageId> <PackageId>LiteCharms.Features</PackageId>
<Version>1.0.19</Version> <Version>1.0.20</Version>
<Authors>Khwezi Mngoma</Authors> <Authors>Khwezi Mngoma</Authors>
<Company>Lite Charms (PTY) Ltd</Company> <Company>Lite Charms (PTY) Ltd</Company>
<Description>Feature components for Lite Charms applications.</Description> <Description>Feature components for Lite Charms applications.</Description>
@@ -12,7 +12,7 @@
<!-- Nuget Package Details --> <!-- Nuget Package Details -->
<PropertyGroup> <PropertyGroup>
<PackageId>LiteCharms.Infrastructure</PackageId> <PackageId>LiteCharms.Infrastructure</PackageId>
<Version>1.0.19</Version> <Version>1.0.20</Version>
<Authors>Khwezi Mngoma</Authors> <Authors>Khwezi Mngoma</Authors>
<Company>Lite Charms (PTY) Ltd</Company> <Company>Lite Charms (PTY) Ltd</Company>
<Description>Infrastructure components for Lite Charms applications.</Description> <Description>Infrastructure components for Lite Charms applications.</Description>
+1 -1
View File
@@ -11,7 +11,7 @@
<!-- Nuget Package Details --> <!-- Nuget Package Details -->
<PropertyGroup> <PropertyGroup>
<PackageId>LiteCharms.Models</PackageId> <PackageId>LiteCharms.Models</PackageId>
<Version>1.0.19</Version> <Version>1.0.20</Version>
<Authors>Khwezi Mngoma</Authors> <Authors>Khwezi Mngoma</Authors>
<Company>Lite Charms (PTY) Ltd</Company> <Company>Lite Charms (PTY) Ltd</Company>
<Description>Shared models for Lite Charms applications.</Description> <Description>Shared models for Lite Charms applications.</Description>
-1
View File
@@ -2,7 +2,6 @@
<Project Path="LiteCharms.Abstractions/LiteCharms.Abstractions.csproj" Id="e080e621-5394-4260-a793-d54178401942" /> <Project Path="LiteCharms.Abstractions/LiteCharms.Abstractions.csproj" Id="e080e621-5394-4260-a793-d54178401942" />
<Project Path="LiteCharms.Entities/LiteCharms.Entities.csproj" /> <Project Path="LiteCharms.Entities/LiteCharms.Entities.csproj" />
<Project Path="LiteCharms.Extensions/LiteCharms.Extensions.csproj" /> <Project Path="LiteCharms.Extensions/LiteCharms.Extensions.csproj" />
<Project Path="LiteCharms.Features/LiteCharms.Features.csproj" />
<Project Path="LiteCharms.Infrastructure/LiteCharms.Infrastructure.csproj" /> <Project Path="LiteCharms.Infrastructure/LiteCharms.Infrastructure.csproj" />
<Project Path="LiteCharms.Models/LiteCharms.Models.csproj" /> <Project Path="LiteCharms.Models/LiteCharms.Models.csproj" />
</Solution> </Solution>