Remove Old Stuffs for Refactor xEvent Service for Kafka and RabbitMQ ...

This commit is contained in:
2026-08-18 00:00:27 +03:30
parent a94013b591
commit 699fc721f5
18 changed files with 296 additions and 989 deletions
+40 -92
View File
@@ -1,26 +1,29 @@
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using xCommons.Extensions;
using xEventService.Configuration;
using xEventService.Constants;
using xEventService.Interfaces;
using xEventService.Models;
using xEventService.Providers;
using xEventService.Extensions;
using xExceptions.Constants;
namespace xEventService.DI {
public static partial class XDIHelperExtension {
namespace xEventService.DI
{
public static partial class XDIHelperExtension
{
/// <summary>
/// Extract EventService Configurations ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XEventServiceConfiguration GetXEventServiceConfigurations (this IConfiguration source) {
public static XEventServiceConfiguration GetXEventServiceConfigurations(
this IConfiguration source
)
{
//
var configSection = source
.GetSection (ConfigurationNodeNames.EVENT_SERVICE_NODE_NAME);
var result = configSection.Get<XEventServiceConfiguration> ();
.GetSection(ConfigurationNodeNames.EVENT_SERVICE_NODE_NAME);
var result = configSection.Get<XEventServiceConfiguration>();
//
return result;
@@ -31,13 +34,14 @@ namespace xEventService.DI {
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
public static void AddXEventServiceConfigurations (
public static void AddXEventServiceConfigurations(
this IServiceCollection services,
IConfiguration configuration
) {
)
{
//
var config = configuration.GetXEventServiceConfigurations ();
services.AddXEventServiceConfigurations (config);
var config = configuration.GetXEventServiceConfigurations();
services.AddXEventServiceConfigurations(config);
}
/// <summary>
@@ -45,96 +49,40 @@ namespace xEventService.DI {
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
public static void AddXEventServiceConfigurations (
public static void AddXEventServiceConfigurations(
this IServiceCollection services,
XEventServiceConfiguration configuration
) {
)
{
//
services.AddSingleton<XEventServiceConfiguration> (configuration);
}
/// <summary>
/// Register Event Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
public static void AddXEventService (
this IServiceCollection services,
IConfiguration configuration
) {
//
// Check Configuration Registered ...
var config = services.GetRegisteredService<XEventServiceConfiguration> ();
if (config.IsNull ()) {
// Validate ...
if (!configuration.IsValid())
{
//
Console.WriteLine ($"XEventService: there is no provided XEventServiceConfiguration, using default ...");
//
// Register Default Configuration ...
services.AddXEventServiceConfigurations (configuration);
Log("Registration Failed, due Invalid Configuration ...");
XException.InvalidConfiguration.Throw();
}
//
// Register IXEventBus ...
var serviceBas = services.GetRegisteredService<IXEventBus> ();
if (serviceBas.IsNull ()) {
services.AddSingleton<IXEventBus, XEventBus> ();
}
// Register Configuration as Singleton ...
services.AddSingleton(configuration);
}
//
#region Private ...
/// <summary>
/// a LogTag for Service ...
/// </summary>
private static string XLogTag = XEventServiceConstants.XEventServiceDILogTag;
/// <summary>
/// Register an Event Handler ...
/// print a log in Console ...
/// </summary>
/// <param name="services"></param>
/// <param name="lifetime"></param>
/// <typeparam name="TEvent"></typeparam>
/// <typeparam name="THandler"></typeparam>
/// <returns></returns>
public static void AddXEventHandler<TEvent, THandler> (
this IServiceCollection services,
ServiceLifetime lifetime = ServiceLifetime.Transient
)
where TEvent : XEvent
where THandler : IXEventHandler<TEvent> {
//
services.Add (new ServiceDescriptor (
serviceType: typeof (THandler),
implementationType: typeof (THandler),
lifetime: lifetime
));
//
services.Add (new ServiceDescriptor (
serviceType: typeof (IXEventHandler<TEvent>),
implementationType: typeof (THandler),
lifetime: lifetime
));
}
/// <summary>
/// Subscribe to specific Event ...
/// </summary>
/// <param name="app"></param>
/// <typeparam name="TEvent"></typeparam>
/// <typeparam name="THandler"></typeparam>
/// <returns></returns>
public static void XEventSubscribe<TEvent, THandler> (
this IApplicationBuilder app,
bool toExchange = true
)
where TEvent : XEvent
where THandler : IXEventHandler<TEvent> {
//
var eventName = typeof (TEvent).Name;
//
// Retrieve EventBus from IOC ...
var eventBus = app.ApplicationServices.GetRequiredService<IXEventBus> ();
//
// Subscribe to Event Handler ...
var isSubscribed = eventBus.Subscribe<TEvent, THandler> ();
Console.WriteLine ($"XEventService: Event Handler subscription result: {eventName} => {isSubscribed} ...");
/// <param name="message"></param>
private static void Log(string message)
{
Console.WriteLine($"{XLogTag} => {message}");
}
#endregion
}
}