From 8958ad5682cfd165847790a87843ef1b4ec775f2 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 7 Dec 2025 16:12:55 +0330 Subject: [PATCH] Add Entity Hub and also Implement DI Extensions for Register Service ... --- DI/XDIHelperExtension.cs | 103 +++++++++++++++++++++++++++++++++++++++ Hubs/XTagEntityHub.cs | 16 ++++++ 2 files changed, 119 insertions(+) create mode 100644 DI/XDIHelperExtension.cs create mode 100644 Hubs/XTagEntityHub.cs diff --git a/DI/XDIHelperExtension.cs b/DI/XDIHelperExtension.cs new file mode 100644 index 0000000..b168cf1 --- /dev/null +++ b/DI/XDIHelperExtension.cs @@ -0,0 +1,103 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using xCommons.Extensions; +using xExceptions.Constants; +using xTagService.Interfaces.Entities; + +namespace xTagService.DI +{ + public static class XDIHelperExtension + { + /// + /// Register Module Provided Service on DI + /// + /// + /// + public static void AddXTagService( + this IServiceCollection services, + ServiceLifetime lifeTime + ) + { + // + AddTagService( + services, + lifeTime + ); + } + + // + #region Private ... + /// + /// a LogTag for XTagService ... + /// + private static string XLogTag = "XTagService"; + + /// + /// print a log in Console ... + /// + /// + private static void Log(string message) + { + Console.WriteLine($"{XLogTag} => {message}"); + } + + /// + /// Register Push Service ... + /// + /// + /// + private static void AddTagService( + IServiceCollection services, + ServiceLifetime lifeTime + ) + { + // + var exception = XException.InvalidArgs.ToException(); ; + + // + // Services ... + var isServicesExists = !services.IsNull(); + if (!isServicesExists) + { + // + Log("AddTagService failed, services not provided ..."); + throw exception; + } + + // + // Lifetime ... + var isLifetimeExists = !lifeTime.IsNull(); + if (!isLifetimeExists) + { + // + Log("AddTagService failed, lifetime not provided ..."); + throw exception; + } + + // + // Check String Repository Exists ... + var isRepositoryExists = !services + .GetRegisteredService() + .IsNull(); + if (!isRepositoryExists) + { + // + Log("AddTagService failed, IXTagRepository not provided ..."); + throw exception; + } + + // + // Register Resource Providers ... + // services.Add(new ServiceDescriptor(typeof(IXWebinarTitleResourceProvider), typeof(XWebinarTitleResourceProvider), lifeTime)); + // services.Add(new ServiceDescriptor(typeof(IXWebinarDescriptionResourceProvider), typeof(XWebinarDescriptionResourceProvider), lifeTime)); + + // + // Register Main Provider ... + // services.Add(new ServiceDescriptor(typeof(IXWebinarProvider), typeof(XWebinarProvider), lifeTime)); + + // + Log("AddTagService Succeed ..."); + } + #endregion + } +} \ No newline at end of file diff --git a/Hubs/XTagEntityHub.cs b/Hubs/XTagEntityHub.cs new file mode 100644 index 0000000..1b3c75c --- /dev/null +++ b/Hubs/XTagEntityHub.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.Logging; +using xPushService.Base; +using xTagService.Models.Entities; + +namespace xTagService.Hubs +{ + public class XTagEntityHub : XBaseEntityHub + { + // + #region Constructor ... + public XTagEntityHub(ILogger logger) : base(logger) + { + } + #endregion + } +} \ No newline at end of file