diff --git a/Directory.Packages.props b/Directory.Packages.props
index 1425903..adc1b31 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -11,6 +11,7 @@
+
@@ -30,8 +31,10 @@
+
+
diff --git a/HelloShop.sln b/HelloShop.sln
index 0e50d99..31a6e5c 100644
--- a/HelloShop.sln
+++ b/HelloShop.sln
@@ -33,6 +33,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloShop.FunctionalTests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloShop.BasketService.UnitTests", "tests\HelloShop.BasketService.UnitTests\HelloShop.BasketService.UnitTests.csproj", "{BE88233A-D6EB-462B-B53C-B588A0BEFAFC}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libraries", "libraries", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloShop.EventBus.Abstractions", "libraries\HelloShop.EventBus.Abstractions\HelloShop.EventBus.Abstractions.csproj", "{9959387D-8C47-462C-808E-A1E865658C3F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloShop.EventBus.Dapr", "libraries\HelloShop.EventBus.Dapr\HelloShop.EventBus.Dapr.csproj", "{2FD0A058-A447-42C7-A00B-711B2D0B3333}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloShop.EventBus.RabbitMQ", "libraries\HelloShop.EventBus.RabbitMQ\HelloShop.EventBus.RabbitMQ.csproj", "{5D403BF6-9267-4B0F-AEB3-2143C8BBA8CD}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloShop.DistributedLock", "libraries\HelloShop.DistributedLock\HelloShop.DistributedLock.csproj", "{86729635-8E31-4C53-81AE-7C410C848219}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloShop.DistributedLock.Dapr", "libraries\HelloShop.DistributedLock.Dapr\HelloShop.DistributedLock.Dapr.csproj", "{37F01A0B-50D6-48BA-8A20-FBADB5524CD7}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -93,6 +105,26 @@ Global
{BE88233A-D6EB-462B-B53C-B588A0BEFAFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE88233A-D6EB-462B-B53C-B588A0BEFAFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE88233A-D6EB-462B-B53C-B588A0BEFAFC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9959387D-8C47-462C-808E-A1E865658C3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9959387D-8C47-462C-808E-A1E865658C3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9959387D-8C47-462C-808E-A1E865658C3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9959387D-8C47-462C-808E-A1E865658C3F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2FD0A058-A447-42C7-A00B-711B2D0B3333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2FD0A058-A447-42C7-A00B-711B2D0B3333}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2FD0A058-A447-42C7-A00B-711B2D0B3333}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2FD0A058-A447-42C7-A00B-711B2D0B3333}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5D403BF6-9267-4B0F-AEB3-2143C8BBA8CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5D403BF6-9267-4B0F-AEB3-2143C8BBA8CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5D403BF6-9267-4B0F-AEB3-2143C8BBA8CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5D403BF6-9267-4B0F-AEB3-2143C8BBA8CD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {86729635-8E31-4C53-81AE-7C410C848219}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {86729635-8E31-4C53-81AE-7C410C848219}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {86729635-8E31-4C53-81AE-7C410C848219}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {86729635-8E31-4C53-81AE-7C410C848219}.Release|Any CPU.Build.0 = Release|Any CPU
+ {37F01A0B-50D6-48BA-8A20-FBADB5524CD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {37F01A0B-50D6-48BA-8A20-FBADB5524CD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {37F01A0B-50D6-48BA-8A20-FBADB5524CD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {37F01A0B-50D6-48BA-8A20-FBADB5524CD7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -111,6 +143,11 @@ Global
{E58F82E2-2E48-459B-A40E-497F24FC6DC1} = {1AD03316-A743-4E9D-B3BC-FB9499D15141}
{6BAA9747-E0D0-41B9-8A1B-88B777498C43} = {29BE158E-825E-48AB-A02D-4E537A5DC502}
{BE88233A-D6EB-462B-B53C-B588A0BEFAFC} = {29BE158E-825E-48AB-A02D-4E537A5DC502}
+ {9959387D-8C47-462C-808E-A1E865658C3F} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
+ {2FD0A058-A447-42C7-A00B-711B2D0B3333} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
+ {5D403BF6-9267-4B0F-AEB3-2143C8BBA8CD} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
+ {86729635-8E31-4C53-81AE-7C410C848219} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
+ {37F01A0B-50D6-48BA-8A20-FBADB5524CD7} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {845545A8-2006-46C3-ABD7-5BDF63F3858C}
diff --git a/src/HelloShop.ServiceDefaults/DistributedLocks/DaprDistributedLock.cs b/libraries/HelloShop.DistributedLock.Dapr/DaprDistributedLock.cs
similarity index 83%
rename from src/HelloShop.ServiceDefaults/DistributedLocks/DaprDistributedLock.cs
rename to libraries/HelloShop.DistributedLock.Dapr/DaprDistributedLock.cs
index 1fdbf45..cd78442 100644
--- a/src/HelloShop.ServiceDefaults/DistributedLocks/DaprDistributedLock.cs
+++ b/libraries/HelloShop.DistributedLock.Dapr/DaprDistributedLock.cs
@@ -4,7 +4,7 @@
using Dapr.Client;
using System.Diagnostics;
-namespace HelloShop.ServiceDefaults.DistributedLocks
+namespace HelloShop.DistributedLock.Dapr
{
public class DaprDistributedLock(DaprClient daprClient) : IDistributedLock
{
@@ -12,13 +12,14 @@ namespace HelloShop.ServiceDefaults.DistributedLocks
{
expiryInSeconds = expiryInSeconds == default ? 60 : expiryInSeconds;
+ // The CallerMemberNameAttribute is used to get the name of the calling method.
string? lockOwner = new StackTrace().GetFrame(1)?.GetMethod()?.DeclaringType?.Name;
-#pragma warning disable CS0618
+#pragma warning disable CS0618
TryLockResponse response = await daprClient.Lock("lockstore", resourceId, lockOwner, expiryInSeconds, cancellationToken);
#pragma warning restore CS0618
return new DaprDistributedLockResult(response);
}
}
-}
+}
\ No newline at end of file
diff --git a/libraries/HelloShop.DistributedLock.Dapr/DaprDistributedLockExtensions.cs b/libraries/HelloShop.DistributedLock.Dapr/DaprDistributedLockExtensions.cs
new file mode 100644
index 0000000..afdfba3
--- /dev/null
+++ b/libraries/HelloShop.DistributedLock.Dapr/DaprDistributedLockExtensions.cs
@@ -0,0 +1,17 @@
+// Copyright (c) HelloShop Corporation. All rights reserved.
+// See the license file in the project root for more information.
+
+using Microsoft.Extensions.DependencyInjection;
+
+namespace HelloShop.DistributedLock.Dapr
+{
+ public static class DaprDistributedLockExtensions
+ {
+ public static IServiceCollection AddDaprDistributedLock(this IServiceCollection services)
+ {
+ services.AddSingleton();
+
+ return services;
+ }
+ }
+}
diff --git a/src/HelloShop.ServiceDefaults/DistributedLocks/DaprDistributedLockResult.cs b/libraries/HelloShop.DistributedLock.Dapr/DaprDistributedLockResult.cs
similarity index 90%
rename from src/HelloShop.ServiceDefaults/DistributedLocks/DaprDistributedLockResult.cs
rename to libraries/HelloShop.DistributedLock.Dapr/DaprDistributedLockResult.cs
index 248a010..b52e867 100644
--- a/src/HelloShop.ServiceDefaults/DistributedLocks/DaprDistributedLockResult.cs
+++ b/libraries/HelloShop.DistributedLock.Dapr/DaprDistributedLockResult.cs
@@ -3,7 +3,7 @@
using Dapr.Client;
-namespace HelloShop.ServiceDefaults.DistributedLocks
+namespace HelloShop.DistributedLock.Dapr
{
#pragma warning disable CS0618
public class DaprDistributedLockResult(TryLockResponse tryLockResponse) : IDistributedLockResult
@@ -15,4 +15,4 @@ namespace HelloShop.ServiceDefaults.DistributedLocks
GC.SuppressFinalize(this);
}
}
-}
\ No newline at end of file
+}
diff --git a/libraries/HelloShop.DistributedLock.Dapr/HelloShop.DistributedLock.Dapr.csproj b/libraries/HelloShop.DistributedLock.Dapr/HelloShop.DistributedLock.Dapr.csproj
new file mode 100644
index 0000000..f942359
--- /dev/null
+++ b/libraries/HelloShop.DistributedLock.Dapr/HelloShop.DistributedLock.Dapr.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/HelloShop.DistributedLock/HelloShop.DistributedLock.csproj b/libraries/HelloShop.DistributedLock/HelloShop.DistributedLock.csproj
new file mode 100644
index 0000000..125f4c9
--- /dev/null
+++ b/libraries/HelloShop.DistributedLock/HelloShop.DistributedLock.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
diff --git a/src/HelloShop.ServiceDefaults/DistributedLocks/IDistributedLock.cs b/libraries/HelloShop.DistributedLock/IDistributedLock.cs
similarity index 86%
rename from src/HelloShop.ServiceDefaults/DistributedLocks/IDistributedLock.cs
rename to libraries/HelloShop.DistributedLock/IDistributedLock.cs
index 31a1a9d..ebc4f7e 100644
--- a/src/HelloShop.ServiceDefaults/DistributedLocks/IDistributedLock.cs
+++ b/libraries/HelloShop.DistributedLock/IDistributedLock.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-namespace HelloShop.ServiceDefaults.DistributedLocks
+namespace HelloShop.DistributedLock
{
public interface IDistributedLock
{
diff --git a/src/HelloShop.ServiceDefaults/DistributedLocks/IDistributedLockResult.cs b/libraries/HelloShop.DistributedLock/IDistributedLockResult.cs
similarity index 78%
rename from src/HelloShop.ServiceDefaults/DistributedLocks/IDistributedLockResult.cs
rename to libraries/HelloShop.DistributedLock/IDistributedLockResult.cs
index d11e2a0..afffba1 100644
--- a/src/HelloShop.ServiceDefaults/DistributedLocks/IDistributedLockResult.cs
+++ b/libraries/HelloShop.DistributedLock/IDistributedLockResult.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-namespace HelloShop.ServiceDefaults.DistributedLocks
+namespace HelloShop.DistributedLock
{
public interface IDistributedLockResult : IAsyncDisposable { }
-}
+}
\ No newline at end of file
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/DistributedEvent.cs b/libraries/HelloShop.EventBus.Abstractions/DistributedEvent.cs
similarity index 89%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/DistributedEvent.cs
rename to libraries/HelloShop.EventBus.Abstractions/DistributedEvent.cs
index 3a1057b..c5d5eae 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/DistributedEvent.cs
+++ b/libraries/HelloShop.EventBus.Abstractions/DistributedEvent.cs
@@ -4,7 +4,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
-namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
+namespace HelloShop.EventBus.Abstractions
{
public record DistributedEvent
{
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/DistributedEventBusBuilderExtensions.cs b/libraries/HelloShop.EventBus.Abstractions/EventBusBuilderExtensions.cs
similarity index 58%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/DistributedEventBusBuilderExtensions.cs
rename to libraries/HelloShop.EventBus.Abstractions/EventBusBuilderExtensions.cs
index e323725..af5ee21 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/DistributedEventBusBuilderExtensions.cs
+++ b/libraries/HelloShop.EventBus.Abstractions/EventBusBuilderExtensions.cs
@@ -5,13 +5,13 @@ using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
using System.Text.Json;
-namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
+namespace HelloShop.EventBus.Abstractions
{
- public static class DistributedEventBusBuilderExtensions
+ public static class EventBusBuilderExtensions
{
- public static IDistributedEventBusBuilder ConfigureJsonOptions(this IDistributedEventBusBuilder eventBusBuilder, Action configure)
+ public static IEventBusBuilder ConfigureJsonOptions(this IEventBusBuilder eventBusBuilder, Action configure)
{
- eventBusBuilder.Services.Configure(o =>
+ eventBusBuilder.Services.Configure(o =>
{
configure(o.JsonSerializerOptions);
});
@@ -19,11 +19,11 @@ namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
return eventBusBuilder;
}
- public static IDistributedEventBusBuilder AddSubscription(this IDistributedEventBusBuilder eventBusBuilder) where TEvent : DistributedEvent where TEventHandler : class, IDistributedEventHandler
+ public static IEventBusBuilder AddSubscription(this IEventBusBuilder eventBusBuilder) where TEvent : DistributedEvent where TEventHandler : class, IDistributedEventHandler
{
eventBusBuilder.Services.AddKeyedTransient(typeof(TEvent));
- eventBusBuilder.Services.Configure(o =>
+ eventBusBuilder.Services.Configure(o =>
{
o.EventTypes[typeof(TEvent).Name] = typeof(TEvent);
});
@@ -31,11 +31,11 @@ namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
return eventBusBuilder;
}
- public static IDistributedEventBusBuilder AddSubscription(this IDistributedEventBusBuilder eventBusBuilder, Type eventType, Type eventHandlerType)
+ public static IEventBusBuilder AddSubscription(this IEventBusBuilder eventBusBuilder, Type eventType, Type eventHandlerType)
{
eventBusBuilder.Services.AddKeyedTransient(typeof(IDistributedEventHandler), eventType, eventHandlerType);
- eventBusBuilder.Services.Configure(o =>
+ eventBusBuilder.Services.Configure(o =>
{
o.EventTypes[eventType.Name] = eventType;
});
@@ -43,7 +43,7 @@ namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
return eventBusBuilder;
}
- public static IDistributedEventBusBuilder AddSubscriptionFromAssembly(this IDistributedEventBusBuilder eventBusBuilder, Assembly? assembly = null)
+ public static IEventBusBuilder AddSubscriptionFromAssembly(this IEventBusBuilder eventBusBuilder, Assembly? assembly = null)
{
assembly ??= Assembly.GetCallingAssembly();
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/DistributedEventBusOptions.cs b/libraries/HelloShop.EventBus.Abstractions/EventBusOptions.cs
similarity index 84%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/DistributedEventBusOptions.cs
rename to libraries/HelloShop.EventBus.Abstractions/EventBusOptions.cs
index d45915a..f2b8020 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/DistributedEventBusOptions.cs
+++ b/libraries/HelloShop.EventBus.Abstractions/EventBusOptions.cs
@@ -4,9 +4,9 @@
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
-namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
+namespace HelloShop.EventBus.Abstractions
{
- public class DistributedEventBusOptions
+ public class EventBusOptions
{
public Dictionary EventTypes { get; } = [];
@@ -17,4 +17,4 @@ namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
TypeInfoResolver = JsonSerializer.IsReflectionEnabledByDefault ? new DefaultJsonTypeInfoResolver() : JsonTypeInfoResolver.Combine()
};
}
-}
+}
\ No newline at end of file
diff --git a/libraries/HelloShop.EventBus.Abstractions/HelloShop.EventBus.Abstractions.csproj b/libraries/HelloShop.EventBus.Abstractions/HelloShop.EventBus.Abstractions.csproj
new file mode 100644
index 0000000..757aebf
--- /dev/null
+++ b/libraries/HelloShop.EventBus.Abstractions/HelloShop.EventBus.Abstractions.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/IDistributedEventHandler.cs b/libraries/HelloShop.EventBus.Abstractions/IDistributedEventHandler.cs
similarity index 89%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/IDistributedEventHandler.cs
rename to libraries/HelloShop.EventBus.Abstractions/IDistributedEventHandler.cs
index f139764..e32b1e7 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/IDistributedEventHandler.cs
+++ b/libraries/HelloShop.EventBus.Abstractions/IDistributedEventHandler.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
+namespace HelloShop.EventBus.Abstractions
{
public interface IDistributedEventHandler
{
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/IDistributedEventBus.cs b/libraries/HelloShop.EventBus.Abstractions/IEventBus.cs
similarity index 69%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/IDistributedEventBus.cs
rename to libraries/HelloShop.EventBus.Abstractions/IEventBus.cs
index 13b1653..2f089f3 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/IDistributedEventBus.cs
+++ b/libraries/HelloShop.EventBus.Abstractions/IEventBus.cs
@@ -1,9 +1,9 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
+namespace HelloShop.EventBus.Abstractions
{
- public interface IDistributedEventBus
+ public interface IEventBus
{
Task PublishAsync(DistributedEvent @event, CancellationToken cancellationToken = default);
}
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/IDistributedEventBusBuilder.cs b/libraries/HelloShop.EventBus.Abstractions/IEventBusBuilder.cs
similarity index 68%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/IDistributedEventBusBuilder.cs
rename to libraries/HelloShop.EventBus.Abstractions/IEventBusBuilder.cs
index 66e3de5..b608d8a 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/Abstractions/IDistributedEventBusBuilder.cs
+++ b/libraries/HelloShop.EventBus.Abstractions/IEventBusBuilder.cs
@@ -3,9 +3,9 @@
using Microsoft.Extensions.DependencyInjection;
-namespace HelloShop.ServiceDefaults.DistributedEvents.Abstractions
+namespace HelloShop.EventBus.Abstractions
{
- public interface IDistributedEventBusBuilder
+ public interface IEventBusBuilder
{
public IServiceCollection Services { get; }
}
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprCloudEvent.cs b/libraries/HelloShop.EventBus.Dapr/DaprCloudEvent.cs
similarity index 91%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprCloudEvent.cs
rename to libraries/HelloShop.EventBus.Dapr/DaprCloudEvent.cs
index fed3bf0..eda884b 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprCloudEvent.cs
+++ b/libraries/HelloShop.EventBus.Dapr/DaprCloudEvent.cs
@@ -4,7 +4,7 @@
using Dapr;
using System.Text.Json.Serialization;
-namespace HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks
+namespace HelloShop.EventBus.Dapr
{
public class DaprCloudEvent(TData data) : CloudEvent(data)
{
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprDistributedEventBus.cs b/libraries/HelloShop.EventBus.Dapr/DaprEventBus.cs
similarity index 70%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprDistributedEventBus.cs
rename to libraries/HelloShop.EventBus.Dapr/DaprEventBus.cs
index 9ad741d..0bf4f09 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprDistributedEventBus.cs
+++ b/libraries/HelloShop.EventBus.Dapr/DaprEventBus.cs
@@ -2,13 +2,13 @@
// See the license file in the project root for more information.
using Dapr.Client;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
-namespace HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks
+namespace HelloShop.EventBus.Dapr
{
- public class DaprDistributedEventBus(DaprClient daprClient, IOptions options, ILogger logger) : IDistributedEventBus
+ public class DaprEventBus(DaprClient daprClient, IOptions options, ILogger logger) : IEventBus
{
public async Task PublishAsync(DistributedEvent @event, CancellationToken cancellationToken = default)
{
@@ -22,4 +22,4 @@ namespace HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks
await daprClient.PublishEventAsync(pubSubName, topicName, data, cancellationToken);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprDistributedEventBusExtensions.cs b/libraries/HelloShop.EventBus.Dapr/DaprEventBusExtensions.cs
similarity index 68%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprDistributedEventBusExtensions.cs
rename to libraries/HelloShop.EventBus.Dapr/DaprEventBusExtensions.cs
index 6554b3f..b4d4526 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprDistributedEventBusExtensions.cs
+++ b/libraries/HelloShop.EventBus.Dapr/DaprEventBusExtensions.cs
@@ -1,9 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using FluentValidation;
-using FluentValidation.Results;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
@@ -14,25 +12,25 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using System.Text.Json;
-namespace HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks
+namespace HelloShop.EventBus.Dapr
{
- public static class DaprDistributedEventBusExtensions
+ public static class DaprEventBusExtensions
{
- private const string DefaultSectionName = "DaprDistributedEventBus";
+ private const string DefaultSectionName = "DaprEventBus";
- public static IDistributedEventBusBuilder AddDaprDistributedEventBus(this IHostApplicationBuilder builder, string sectionName = DefaultSectionName)
+ public static IEventBusBuilder AddDaprEventBus(this IHostApplicationBuilder builder, string sectionName = DefaultSectionName)
{
ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddDaprClient();
- DaprDistributedEventBusOptions daprOptions = new();
+ DaprEventBusOptions daprOptions = new();
builder.Configuration.GetSection(sectionName).Bind(daprOptions);
builder.Services.AddSingleton(Options.Create(daprOptions));
- builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
if (daprOptions.RequireAuthenticatedDaprApiToken)
{
@@ -43,18 +41,18 @@ namespace HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks
return new DistributedEventBusBuilder(builder.Services);
}
- private class DistributedEventBusBuilder(IServiceCollection services) : IDistributedEventBusBuilder
+ private class DistributedEventBusBuilder(IServiceCollection services) : IEventBusBuilder
{
public IServiceCollection Services => services;
}
- public static WebApplication MapDaprDistributedEventBus(this WebApplication app)
+ public static WebApplication MapDaprEventBus(this WebApplication app)
{
ArgumentNullException.ThrowIfNull(app);
- var eventBusOptions = app.Services.GetRequiredService>().Value;
+ var eventBusOptions = app.Services.GetRequiredService>().Value;
- var daprEventBusOptions = app.Services.GetRequiredService>().Value;
+ var daprEventBusOptions = app.Services.GetRequiredService>().Value;
RouteHandlerBuilder routeHandler = app.MapPost($"/api/DistributedEvents", async (DaprCloudEvent cloudEvent, IHttpContextAccessor contextAccessor) =>
{
@@ -72,16 +70,6 @@ namespace HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks
return Results.BadRequest();
}
- if (httpContext.RequestServices.GetService(typeof(IValidator<>).MakeGenericType(eventType)) is IValidator validator)
- {
- ValidationResult validationResult = await validator.ValidateAsync(new ValidationContext(@event));
-
- if (!validationResult.IsValid)
- {
- return Results.ValidationProblem(validationResult.ToDictionary());
- }
- }
-
foreach (var handler in httpContext.RequestServices.GetKeyedServices(eventType))
{
await handler.HandleAsync(@event);
@@ -91,13 +79,13 @@ namespace HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks
}).WithTags(nameof(DistributedEvent));
+ app.MapSubscribeHandler();
+
foreach (var subscription in eventBusOptions.EventTypes)
{
routeHandler.WithTopic(daprEventBusOptions.PubSubName, subscription.Key, enableRawPayload: false);
}
- app.MapSubscribeHandler();
-
return app;
}
}
diff --git a/src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprDistributedEventBusOptions.cs b/libraries/HelloShop.EventBus.Dapr/DaprEventBusOptions.cs
similarity index 64%
rename from src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprDistributedEventBusOptions.cs
rename to libraries/HelloShop.EventBus.Dapr/DaprEventBusOptions.cs
index 6680ae4..ae77ce4 100644
--- a/src/HelloShop.ServiceDefaults/DistributedEvents/DaprBuildingBlocks/DaprDistributedEventBusOptions.cs
+++ b/libraries/HelloShop.EventBus.Dapr/DaprEventBusOptions.cs
@@ -1,12 +1,10 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-namespace HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks
+namespace HelloShop.EventBus.Dapr
{
- public class DaprDistributedEventBusOptions
+ public class DaprEventBusOptions
{
- public const string SectionName = "DaprDistributedEventBus";
-
public string PubSubName { get; set; } = "event-bus-pubsub";
public bool RequireAuthenticatedDaprApiToken { get; set; } = false;
diff --git a/libraries/HelloShop.EventBus.Dapr/HelloShop.EventBus.Dapr.csproj b/libraries/HelloShop.EventBus.Dapr/HelloShop.EventBus.Dapr.csproj
new file mode 100644
index 0000000..0b35680
--- /dev/null
+++ b/libraries/HelloShop.EventBus.Dapr/HelloShop.EventBus.Dapr.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/HelloShop.EventBus.RabbitMQ/HelloShop.EventBus.RabbitMQ.csproj b/libraries/HelloShop.EventBus.RabbitMQ/HelloShop.EventBus.RabbitMQ.csproj
new file mode 100644
index 0000000..51bc6db
--- /dev/null
+++ b/libraries/HelloShop.EventBus.RabbitMQ/HelloShop.EventBus.RabbitMQ.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net9.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/HelloShop.EventBus.RabbitMQ/RabbitMQEventBus.cs b/libraries/HelloShop.EventBus.RabbitMQ/RabbitMQEventBus.cs
new file mode 100644
index 0000000..6d3dc18
--- /dev/null
+++ b/libraries/HelloShop.EventBus.RabbitMQ/RabbitMQEventBus.cs
@@ -0,0 +1,121 @@
+// Copyright (c) HelloShop Corporation. All rights reserved.
+// See the license file in the project root for more information.
+
+using HelloShop.EventBus.Abstractions;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using Polly;
+using Polly.Retry;
+using RabbitMQ.Client;
+using RabbitMQ.Client.Events;
+using RabbitMQ.Client.Exceptions;
+using System.Net.Sockets;
+using System.Text;
+using System.Text.Json;
+
+namespace HelloShop.EventBus.RabbitMQ
+{
+ public sealed class RabbitMQEventBus(ILogger logger, IServiceProvider serviceProvider, IOptions rabbitMQEventBusOptions, IOptions eventBusOptions) : IEventBus, IDisposable, IHostedService
+ {
+ private readonly ResiliencePipeline _pipeline = CreateResiliencePipeline(rabbitMQEventBusOptions.Value.RetryCount);
+ private readonly string _queueName = rabbitMQEventBusOptions.Value.QueueName;
+ private readonly string _exchangeName = rabbitMQEventBusOptions.Value.ExchangeName;
+ private readonly EventBusOptions _eventBusOptions = eventBusOptions.Value;
+
+ private IConnection? _rabbitMQConnection;
+ private IModel? _consumerChannel;
+
+ public Task StartAsync(CancellationToken cancellationToken)
+ {
+ Task.Factory.StartNew(() =>
+ {
+ try
+ {
+ _rabbitMQConnection = serviceProvider.GetRequiredService();
+ _consumerChannel = _rabbitMQConnection.CreateModel();
+ _consumerChannel.ExchangeDeclare(exchange: _exchangeName, type: ExchangeType.Direct);
+ _consumerChannel.QueueDeclare(queue: _queueName, durable: true, exclusive: false, autoDelete: false, arguments: null);
+
+ var consumer = new AsyncEventingBasicConsumer(_consumerChannel);
+ consumer.Received += OnMessageReceivedAsync;
+ _consumerChannel.BasicConsume(queue: _queueName, autoAck: false, consumer: consumer);
+
+ foreach (var (eventName, _) in _eventBusOptions.EventTypes)
+ {
+ _consumerChannel.QueueBind(queue: _queueName, exchange: _exchangeName, routingKey: eventName);
+ }
+ }
+ catch (Exception ex)
+ {
+ logger.LogError(ex, "An error occurred while starting the RabbitMQ event bus.");
+ }
+ }, TaskCreationOptions.LongRunning);
+
+ return Task.CompletedTask;
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
+
+ public void Dispose() => _consumerChannel?.Dispose();
+
+ public Task PublishAsync(DistributedEvent @event, CancellationToken cancellationToken = default)
+ {
+ string routingKey = @event.GetType().Name;
+
+ using var channel = _rabbitMQConnection?.CreateModel() ?? throw new InvalidOperationException("RabbitMQ connection is not available.");
+
+ channel.ExchangeDeclare(exchange: _exchangeName, type: ExchangeType.Direct);
+
+ var body = JsonSerializer.SerializeToUtf8Bytes(@event, @event.GetType(), _eventBusOptions.JsonSerializerOptions);
+
+ return _pipeline.Execute(() =>
+ {
+ IBasicProperties properties = channel.CreateBasicProperties();
+ properties.DeliveryMode = 2;
+ channel.BasicPublish(exchange: _exchangeName, routingKey: routingKey, mandatory: true, basicProperties: properties, body: body);
+ return Task.CompletedTask;
+ });
+ }
+
+ private async Task OnMessageReceivedAsync(object sender, BasicDeliverEventArgs eventArgs)
+ {
+ string eventName = eventArgs.RoutingKey;
+ string message = Encoding.UTF8.GetString(eventArgs.Body.Span);
+
+ if (!_eventBusOptions.EventTypes.TryGetValue(eventName, out var eventType))
+ {
+ return;
+ }
+
+ await using var scope = serviceProvider.CreateAsyncScope();
+
+ var distributedEvent = JsonSerializer.Deserialize(message, eventType, _eventBusOptions.JsonSerializerOptions) as DistributedEvent;
+
+ foreach (var handler in scope.ServiceProvider.GetKeyedServices(eventType))
+ {
+ if (distributedEvent is not null)
+ {
+ await handler.HandleAsync(distributedEvent);
+ }
+ }
+
+ _consumerChannel?.BasicAck(eventArgs.DeliveryTag, multiple: false);
+ }
+
+ private static ResiliencePipeline CreateResiliencePipeline(int retryCount)
+ {
+ var retryOptions = new RetryStrategyOptions
+ {
+ ShouldHandle = new PredicateBuilder().Handle().Handle(),
+ MaxRetryAttempts = retryCount,
+ DelayGenerator = (context) => ValueTask.FromResult(GenerateDelay(context.AttemptNumber))
+ };
+
+ return new ResiliencePipelineBuilder().AddRetry(retryOptions).Build();
+
+ static TimeSpan? GenerateDelay(int attempt) => TimeSpan.FromSeconds(Math.Pow(2, attempt));
+ }
+ }
+}
\ No newline at end of file
diff --git a/libraries/HelloShop.EventBus.RabbitMQ/RabbitMQEventBusExtensions.cs b/libraries/HelloShop.EventBus.RabbitMQ/RabbitMQEventBusExtensions.cs
new file mode 100644
index 0000000..ad094f8
--- /dev/null
+++ b/libraries/HelloShop.EventBus.RabbitMQ/RabbitMQEventBusExtensions.cs
@@ -0,0 +1,36 @@
+// Copyright (c) HelloShop Corporation. All rights reserved.
+// See the license file in the project root for more information.
+
+using HelloShop.EventBus.Abstractions;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+
+namespace HelloShop.EventBus.RabbitMQ
+{
+ public static class RabbitMQEventBusExtensions
+ {
+ private const string DefaultSectionName = "RabbitMQEventBus";
+
+ public static IEventBusBuilder AddRabbitMqEventBus(this IHostApplicationBuilder builder, string connectionName, string sectionName = DefaultSectionName)
+ {
+ ArgumentNullException.ThrowIfNull(builder);
+
+ builder.AddRabbitMQClient(connectionName, configureConnectionFactory: factory =>
+ {
+ factory.DispatchConsumersAsync = true;
+ });
+
+ builder.Services.Configure(builder.Configuration.GetSection(sectionName));
+
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton(sp => (RabbitMQEventBus)sp.GetRequiredService());
+
+ return new EventBusBuilder(builder.Services);
+ }
+
+ private class EventBusBuilder(IServiceCollection services) : IEventBusBuilder
+ {
+ public IServiceCollection Services => services;
+ }
+ }
+}
diff --git a/libraries/HelloShop.EventBus.RabbitMQ/RabbitMQEventBusOptions.cs b/libraries/HelloShop.EventBus.RabbitMQ/RabbitMQEventBusOptions.cs
new file mode 100644
index 0000000..e679898
--- /dev/null
+++ b/libraries/HelloShop.EventBus.RabbitMQ/RabbitMQEventBusOptions.cs
@@ -0,0 +1,14 @@
+// Copyright (c) HelloShop Corporation. All rights reserved.
+// See the license file in the project root for more information.
+
+namespace HelloShop.EventBus.RabbitMQ
+{
+ public class RabbitMQEventBusOptions
+ {
+ public string ExchangeName { get; set; } = "event-bus-exchange";
+
+ public required string QueueName { get; set; }
+
+ public int RetryCount { get; set; } = 10;
+ }
+}
diff --git a/src/HelloShop.BasketService/DistributedEvents/EventHandling/OrderStartedDistributedEventHandler.cs b/src/HelloShop.BasketService/DistributedEvents/EventHandling/OrderStartedDistributedEventHandler.cs
index 3d0eabb..b67c42b 100644
--- a/src/HelloShop.BasketService/DistributedEvents/EventHandling/OrderStartedDistributedEventHandler.cs
+++ b/src/HelloShop.BasketService/DistributedEvents/EventHandling/OrderStartedDistributedEventHandler.cs
@@ -3,7 +3,7 @@
using HelloShop.BasketService.DistributedEvents.Events;
using HelloShop.BasketService.Repositories;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.BasketService.DistributedEvents.EventHandling
{
diff --git a/src/HelloShop.BasketService/DistributedEvents/Events/OrderStartedDistributedEvent.cs b/src/HelloShop.BasketService/DistributedEvents/Events/OrderStartedDistributedEvent.cs
index 0cc0741..bbd5c13 100644
--- a/src/HelloShop.BasketService/DistributedEvents/Events/OrderStartedDistributedEvent.cs
+++ b/src/HelloShop.BasketService/DistributedEvents/Events/OrderStartedDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.BasketService.DistributedEvents.Events
{
diff --git a/src/HelloShop.BasketService/HelloShop.BasketService.csproj b/src/HelloShop.BasketService/HelloShop.BasketService.csproj
index e70558f..2b317ee 100644
--- a/src/HelloShop.BasketService/HelloShop.BasketService.csproj
+++ b/src/HelloShop.BasketService/HelloShop.BasketService.csproj
@@ -20,6 +20,7 @@
+
\ No newline at end of file
diff --git a/src/HelloShop.BasketService/Program.cs b/src/HelloShop.BasketService/Program.cs
index db9f6a6..a7630eb 100644
--- a/src/HelloShop.BasketService/Program.cs
+++ b/src/HelloShop.BasketService/Program.cs
@@ -5,8 +5,8 @@ using HelloShop.BasketService.DistributedEvents.EventHandling;
using HelloShop.BasketService.DistributedEvents.Events;
using HelloShop.BasketService.Repositories;
using HelloShop.BasketService.Services;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
-using HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks;
+using HelloShop.EventBus.Abstractions;
+using HelloShop.EventBus.Dapr;
using HelloShop.ServiceDefaults.Extensions;
using Microsoft.IdentityModel.Tokens;
using System.Text;
@@ -41,7 +41,7 @@ builder.Services.AddLocalization().AddPermissionDefinitions();
builder.Services.AddAuthorization().AddRemotePermissionChecker().AddCustomAuthorization();
builder.Services.AddCors();
-builder.AddDaprDistributedEventBus().AddSubscription();
+builder.AddDaprEventBus().AddSubscription();
// End addd extensions services to the container.
@@ -55,7 +55,7 @@ app.MapDefaultEndpoints();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client.").WithTags("Welcome");
// Configure extensions request pipeline.
-app.MapDaprDistributedEventBus();
+app.MapDaprEventBus();
app.UseAuthentication().UseAuthorization();
app.MapGrpcService();
app.MapGrpcService();
diff --git a/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderPaymentSucceededDistributedEventHandler.cs b/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderPaymentSucceededDistributedEventHandler.cs
index 6e27c61..709bff4 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderPaymentSucceededDistributedEventHandler.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderPaymentSucceededDistributedEventHandler.cs
@@ -1,11 +1,11 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.EventBus.Abstractions;
using HelloShop.OrderingService.DistributedEvents.Events;
using HelloShop.OrderingService.Entities.Orders;
using HelloShop.OrderingService.Infrastructure;
using HelloShop.OrderingService.Services;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
using Microsoft.EntityFrameworkCore;
namespace HelloShop.OrderingService.DistributedEvents.EventHandling
diff --git a/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderStockConfirmedDistributedEventHandler.cs b/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderStockConfirmedDistributedEventHandler.cs
index 2d3e463..e8138d0 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderStockConfirmedDistributedEventHandler.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderStockConfirmedDistributedEventHandler.cs
@@ -1,10 +1,10 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.EventBus.Abstractions;
using HelloShop.OrderingService.DistributedEvents.Events;
using HelloShop.OrderingService.Entities.Orders;
using HelloShop.OrderingService.Infrastructure;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
namespace HelloShop.OrderingService.DistributedEvents.EventHandling
{
diff --git a/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderStockRejectedDistributedEventHandler.cs b/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderStockRejectedDistributedEventHandler.cs
index 43ad9b2..88ad140 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderStockRejectedDistributedEventHandler.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/EventHandling/OrderStockRejectedDistributedEventHandler.cs
@@ -1,10 +1,10 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.EventBus.Abstractions;
using HelloShop.OrderingService.DistributedEvents.Events;
using HelloShop.OrderingService.Entities.Orders;
using HelloShop.OrderingService.Infrastructure;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
namespace HelloShop.OrderingService.DistributedEvents.EventHandling
{
diff --git a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderAwaitingValidationDistributedEvent.cs b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderAwaitingValidationDistributedEvent.cs
index b78a7b8..67d6c4f 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderAwaitingValidationDistributedEvent.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderAwaitingValidationDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.OrderingService.DistributedEvents.Events
{
diff --git a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaidDistributedEvent.cs b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaidDistributedEvent.cs
index 1f928a7..fd995e7 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaidDistributedEvent.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaidDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.OrderingService.DistributedEvents.Events
{
diff --git a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaymentFailedDistributedEvent.cs b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaymentFailedDistributedEvent.cs
index 248f5b3..a0f21d7 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaymentFailedDistributedEvent.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaymentFailedDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.OrderingService.DistributedEvents.Events
{
diff --git a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaymentSucceededDistributedEvent.cs b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaymentSucceededDistributedEvent.cs
index 07e0cb4..907c6f5 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaymentSucceededDistributedEvent.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderPaymentSucceededDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.OrderingService.DistributedEvents.Events
{
diff --git a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStartedDistributedEvent.cs b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStartedDistributedEvent.cs
index ad7d2d6..6919e03 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStartedDistributedEvent.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStartedDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.OrderingService.DistributedEvents.Events
{
diff --git a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStockConfirmedDistributedEvent.cs b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStockConfirmedDistributedEvent.cs
index 5684b76..a208e77 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStockConfirmedDistributedEvent.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStockConfirmedDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.OrderingService.DistributedEvents.Events
{
diff --git a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStockRejectedDistributedEvent.cs b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStockRejectedDistributedEvent.cs
index 1cfcacb..dd9d9ea 100644
--- a/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStockRejectedDistributedEvent.cs
+++ b/src/HelloShop.OrderingService/DistributedEvents/Events/OrderStockRejectedDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.OrderingService.DistributedEvents.Events
{
diff --git a/src/HelloShop.OrderingService/Entities/EventLogs/DistributedEventLog.cs b/src/HelloShop.OrderingService/Entities/EventLogs/DistributedEventLog.cs
index 0c66301..d6d11a7 100644
--- a/src/HelloShop.OrderingService/Entities/EventLogs/DistributedEventLog.cs
+++ b/src/HelloShop.OrderingService/Entities/EventLogs/DistributedEventLog.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
using System.Diagnostics.CodeAnalysis;
namespace HelloShop.OrderingService.Entities.EventLogs
diff --git a/src/HelloShop.OrderingService/Extensions/Extensions.cs b/src/HelloShop.OrderingService/Extensions/Extensions.cs
index d8b6da9..8d96300 100644
--- a/src/HelloShop.OrderingService/Extensions/Extensions.cs
+++ b/src/HelloShop.OrderingService/Extensions/Extensions.cs
@@ -1,14 +1,14 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.EventBus.Abstractions;
+using HelloShop.EventBus.Dapr;
using HelloShop.OrderingService.Behaviors;
using HelloShop.OrderingService.Constants;
using HelloShop.OrderingService.Infrastructure;
using HelloShop.OrderingService.Queries;
using HelloShop.OrderingService.Services;
using HelloShop.OrderingService.Workers;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
-using HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks;
using HelloShop.ServiceDefaults.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
@@ -57,7 +57,7 @@ namespace HelloShop.OrderingService.Extensions
builder.Services.AddTransient().AddTransient();
- builder.AddDaprDistributedEventBus().AddSubscriptionFromAssembly();
+ builder.AddDaprEventBus().AddSubscriptionFromAssembly();
builder.Services.Configure(hostOptions =>
{
@@ -79,7 +79,7 @@ namespace HelloShop.OrderingService.Extensions
app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
app.UseOpenApi();
app.UseDataSeedingProviders();
- app.MapDaprDistributedEventBus();
+ app.MapDaprEventBus();
return app;
}
diff --git a/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj b/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj
index cf58f42..5ad96cf 100644
--- a/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj
+++ b/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj
@@ -5,6 +5,7 @@
enable
+
diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/EventLogs/DistributedEventLogEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/EventLogs/DistributedEventLogEntityTypeConfiguration.cs
index a9f3c94..35b00a5 100644
--- a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/EventLogs/DistributedEventLogEntityTypeConfiguration.cs
+++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/EventLogs/DistributedEventLogEntityTypeConfiguration.cs
@@ -1,8 +1,8 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.EventBus.Abstractions;
using HelloShop.OrderingService.Entities.EventLogs;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.Text.Json;
diff --git a/src/HelloShop.OrderingService/Services/DistributedEventService.cs b/src/HelloShop.OrderingService/Services/DistributedEventService.cs
index 8d02035..5d6ce0e 100644
--- a/src/HelloShop.OrderingService/Services/DistributedEventService.cs
+++ b/src/HelloShop.OrderingService/Services/DistributedEventService.cs
@@ -1,13 +1,13 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.EventBus.Abstractions;
using HelloShop.OrderingService.Entities.EventLogs;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
using Microsoft.EntityFrameworkCore;
namespace HelloShop.OrderingService.Services
{
- public class DistributedEventService(TContext dbContext, IDistributedEventBus distributedEventBus, ILogger> logger) : IDistributedEventService, IDisposable where TContext : DbContext
+ public class DistributedEventService(TContext dbContext, IEventBus distributedEventBus, ILogger> logger) : IDistributedEventService, IDisposable where TContext : DbContext
{
private volatile bool _disposedValue;
diff --git a/src/HelloShop.OrderingService/Services/IDistributedEventService.cs b/src/HelloShop.OrderingService/Services/IDistributedEventService.cs
index 2e24319..40f70b8 100644
--- a/src/HelloShop.OrderingService/Services/IDistributedEventService.cs
+++ b/src/HelloShop.OrderingService/Services/IDistributedEventService.cs
@@ -1,8 +1,8 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.EventBus.Abstractions;
using HelloShop.OrderingService.Entities.EventLogs;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
namespace HelloShop.OrderingService.Services
{
diff --git a/src/HelloShop.OrderingService/Workers/GracePeriodWorker.cs b/src/HelloShop.OrderingService/Workers/GracePeriodWorker.cs
index ed476ac..8a77bc3 100644
--- a/src/HelloShop.OrderingService/Workers/GracePeriodWorker.cs
+++ b/src/HelloShop.OrderingService/Workers/GracePeriodWorker.cs
@@ -2,10 +2,10 @@
// See the license file in the project root for more information.
+using HelloShop.EventBus.Abstractions;
using HelloShop.OrderingService.DistributedEvents.Events;
using HelloShop.OrderingService.Entities.Orders;
using HelloShop.OrderingService.Infrastructure;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
using Microsoft.EntityFrameworkCore;
namespace HelloShop.OrderingService.Workers
@@ -23,7 +23,7 @@ namespace HelloShop.OrderingService.Workers
using var scope = serviceScopeFactory.CreateAsyncScope();
var dbContext = scope.ServiceProvider.GetRequiredService();
- var distributedEventBus = scope.ServiceProvider.GetRequiredService();
+ var distributedEventBus = scope.ServiceProvider.GetRequiredService();
DateTimeOffset dateTimeOffset = timeProvider.GetUtcNow().AddMinutes(-1);
diff --git a/src/HelloShop.OrderingService/Workers/PaymentWorker.cs b/src/HelloShop.OrderingService/Workers/PaymentWorker.cs
index 05cda9f..e1f4ce2 100644
--- a/src/HelloShop.OrderingService/Workers/PaymentWorker.cs
+++ b/src/HelloShop.OrderingService/Workers/PaymentWorker.cs
@@ -1,10 +1,10 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.EventBus.Abstractions;
using HelloShop.OrderingService.DistributedEvents.Events;
using HelloShop.OrderingService.Entities.Orders;
using HelloShop.OrderingService.Infrastructure;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
using Microsoft.EntityFrameworkCore;
namespace HelloShop.OrderingService.Workers
@@ -23,7 +23,7 @@ namespace HelloShop.OrderingService.Workers
using var scope = serviceScopeFactory.CreateAsyncScope();
var dbContext = scope.ServiceProvider.GetRequiredService();
- var distributedEventBus = scope.ServiceProvider.GetRequiredService();
+ var distributedEventBus = scope.ServiceProvider.GetRequiredService();
bool paymentSucceeded = Random.Shared.NextDouble() > 0.3;
diff --git a/src/HelloShop.ProductService/DistributedEvents/EventHandling/OrderAwaitingValidationDistributedEventHandler.cs b/src/HelloShop.ProductService/DistributedEvents/EventHandling/OrderAwaitingValidationDistributedEventHandler.cs
index 5aa86ed..46e6cc6 100644
--- a/src/HelloShop.ProductService/DistributedEvents/EventHandling/OrderAwaitingValidationDistributedEventHandler.cs
+++ b/src/HelloShop.ProductService/DistributedEvents/EventHandling/OrderAwaitingValidationDistributedEventHandler.cs
@@ -1,15 +1,15 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.DistributedLock;
+using HelloShop.EventBus.Abstractions;
using HelloShop.ProductService.DistributedEvents.Events;
using HelloShop.ProductService.Entities.Products;
using HelloShop.ProductService.Infrastructure;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
-using HelloShop.ServiceDefaults.DistributedLocks;
namespace HelloShop.ProductService.DistributedEvents.EventHandling
{
- public class OrderAwaitingValidationDistributedEventHandler(ProductServiceDbContext dbContext, IDistributedEventBus distributedEventBus, IDistributedLock distributedLock, ILogger logger) : IDistributedEventHandler
+ public class OrderAwaitingValidationDistributedEventHandler(ProductServiceDbContext dbContext, IEventBus distributedEventBus, IDistributedLock distributedLock, ILogger logger) : IDistributedEventHandler
{
public async Task HandleAsync(OrderAwaitingValidationDistributedEvent @event)
{
diff --git a/src/HelloShop.ProductService/DistributedEvents/EventHandling/OrderPaidDistributedEventHandler.cs b/src/HelloShop.ProductService/DistributedEvents/EventHandling/OrderPaidDistributedEventHandler.cs
index 9e61f28..56ffb00 100644
--- a/src/HelloShop.ProductService/DistributedEvents/EventHandling/OrderPaidDistributedEventHandler.cs
+++ b/src/HelloShop.ProductService/DistributedEvents/EventHandling/OrderPaidDistributedEventHandler.cs
@@ -1,11 +1,11 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.DistributedLock;
+using HelloShop.EventBus.Abstractions;
using HelloShop.ProductService.DistributedEvents.Events;
using HelloShop.ProductService.Entities.Products;
using HelloShop.ProductService.Infrastructure;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
-using HelloShop.ServiceDefaults.DistributedLocks;
namespace HelloShop.ProductService.DistributedEvents.EventHandling
{
diff --git a/src/HelloShop.ProductService/DistributedEvents/Events/OrderAwaitingValidationDistributedEvent.cs b/src/HelloShop.ProductService/DistributedEvents/Events/OrderAwaitingValidationDistributedEvent.cs
index 6575ebe..48daad1 100644
--- a/src/HelloShop.ProductService/DistributedEvents/Events/OrderAwaitingValidationDistributedEvent.cs
+++ b/src/HelloShop.ProductService/DistributedEvents/Events/OrderAwaitingValidationDistributedEvent.cs
@@ -1,7 +1,8 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.ProductService.DistributedEvents.Events
{
diff --git a/src/HelloShop.ProductService/DistributedEvents/Events/OrderPaidDistributedEvent.cs b/src/HelloShop.ProductService/DistributedEvents/Events/OrderPaidDistributedEvent.cs
index 240864b..e716463 100644
--- a/src/HelloShop.ProductService/DistributedEvents/Events/OrderPaidDistributedEvent.cs
+++ b/src/HelloShop.ProductService/DistributedEvents/Events/OrderPaidDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.ProductService.DistributedEvents.Events
{
diff --git a/src/HelloShop.ProductService/DistributedEvents/Events/OrderStockConfirmedDistributedEvent.cs b/src/HelloShop.ProductService/DistributedEvents/Events/OrderStockConfirmedDistributedEvent.cs
index 89f60d7..3765df6 100644
--- a/src/HelloShop.ProductService/DistributedEvents/Events/OrderStockConfirmedDistributedEvent.cs
+++ b/src/HelloShop.ProductService/DistributedEvents/Events/OrderStockConfirmedDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.ProductService.DistributedEvents.Events
{
diff --git a/src/HelloShop.ProductService/DistributedEvents/Events/OrderStockRejectedDistributedEvent.cs b/src/HelloShop.ProductService/DistributedEvents/Events/OrderStockRejectedDistributedEvent.cs
index e140898..4972a22 100644
--- a/src/HelloShop.ProductService/DistributedEvents/Events/OrderStockRejectedDistributedEvent.cs
+++ b/src/HelloShop.ProductService/DistributedEvents/Events/OrderStockRejectedDistributedEvent.cs
@@ -1,7 +1,7 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
+using HelloShop.EventBus.Abstractions;
namespace HelloShop.ProductService.DistributedEvents.Events
{
diff --git a/src/HelloShop.ProductService/HelloShop.ProductService.csproj b/src/HelloShop.ProductService/HelloShop.ProductService.csproj
index f5c2d27..9795c77 100644
--- a/src/HelloShop.ProductService/HelloShop.ProductService.csproj
+++ b/src/HelloShop.ProductService/HelloShop.ProductService.csproj
@@ -5,6 +5,8 @@
enable
+
+
diff --git a/src/HelloShop.ProductService/Program.cs b/src/HelloShop.ProductService/Program.cs
index 8e2448e..61b8c36 100644
--- a/src/HelloShop.ProductService/Program.cs
+++ b/src/HelloShop.ProductService/Program.cs
@@ -1,11 +1,11 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
+using HelloShop.DistributedLock.Dapr;
+using HelloShop.EventBus.Abstractions;
+using HelloShop.EventBus.Dapr;
using HelloShop.ProductService.Constants;
using HelloShop.ProductService.Infrastructure;
-using HelloShop.ServiceDefaults.DistributedEvents.Abstractions;
-using HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks;
-using HelloShop.ServiceDefaults.DistributedLocks;
using HelloShop.ServiceDefaults.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
@@ -42,8 +42,8 @@ builder.Services.AddOpenApi();
builder.Services.AddModelMapper().AddModelValidator();
builder.Services.AddLocalization().AddPermissionDefinitions();
builder.Services.AddAuthorization().AddRemotePermissionChecker().AddCustomAuthorization();
-builder.AddDaprDistributedEventBus().AddSubscriptionFromAssembly();
-builder.Services.AddSingleton();
+builder.AddDaprEventBus().AddSubscriptionFromAssembly();
+builder.Services.AddDaprDistributedLock();
builder.Services.AddSingleton(TimeProvider.System);
// End addd extensions services to the container.
@@ -62,7 +62,7 @@ app.UseDataSeedingProviders();
app.UseCustomLocalization();
app.UseOpenApi();
app.MapGroup("api/Permissions").MapPermissionDefinitions("Permissions");
-app.MapDaprDistributedEventBus();
+app.MapDaprEventBus();
// End configure extensions request pipeline.
app.Run();