add Push Notification Related to XBotUser entitiy, and some missing Providers and also Registration in DI Extensions ...

This commit is contained in:
2026-11-11 18:06:36 +03:30
parent 1e2eb030e8
commit ed1cf5e073
5 changed files with 258 additions and 21 deletions
@@ -0,0 +1,9 @@
namespace xBotService.Configuration
{
public class XBotServiceConfiguration
{
public string Token { get; set; }
public string BaseRoute { get; set; }
public string SendAlertRoute { get; set; }
}
}
+204 -21
View File
@@ -1,70 +1,229 @@
using System; using System;
using xDataService.Db; using xDataService.Db;
using xDataService.DI; using xDataService.DI;
using xPushService.DI;
using xCommons.Helpers; using xCommons.Helpers;
using xCommons.Extensions; using xCommons.Extensions;
using xDataService.Models; using xDataService.Models;
using xPushService.Helpers;
using xExceptions.Constants; using xExceptions.Constants;
using xBotService.Constants; using xBotService.Constants;
using xBotService.Providers;
using xDataService.Constants; using xDataService.Constants;
using xBotService.Interfaces;
using XBotUserService.Helpers; using XBotUserService.Helpers;
using xHttpService.Interfaces; using xHttpService.Interfaces;
using xBotService.Configuration;
using xBotService.Providers.Dtos; using xBotService.Providers.Dtos;
using xBotService.Interfaces.Dtos;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using xBotService.Providers.Entities;
using xBotService.Interfaces.Entities;
using Microsoft.Extensions.Configuration;
using xBotService.Interfaces.Entities.Dtos; using xBotService.Interfaces.Entities.Dtos;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ConfigurationNodeNames = xBotService.Constants.ConfigurationNodeNames;
namespace xBotService.DI namespace xBotService.DI
{ {
public static class XDIHelperExtension public static class XDIHelperExtension
{ {
/// <summary> /// <summary>
/// Register XBotService /// Retrieve Bot Service Configuration ...
/// </summary> /// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XBotServiceConfiguration GetXBotServiceConfiguration(
this IConfiguration source
)
{
//
var section = source
.GetSection(ConfigurationNodeNames.BOT_SERVICE_NODE);
//
var result = section.Get<XBotServiceConfiguration>();
if (result.IsNull())
{
result = new();
}
//
return result;
}
/// <summary>
/// Extract Service Configurations and Register it ...
/// </summary>
/// <param name="source"></param>
/// <param name="configuration"></param>
public static void AddXBotServiceConfiguration(
this IServiceCollection source,
IConfiguration configuration
)
{
//
var config = configuration.GetXBotServiceConfiguration();
source.AddXBotServiceConfiguration(config);
}
/// <summary>
/// Register Service Configuration ...
/// </summary>
/// <param name="source"></param>
/// <param name="configuration"></param>
public static void AddXBotServiceConfiguration(
this IServiceCollection source,
XBotServiceConfiguration configuration
)
{
//
if (configuration.IsNullOrDefault())
{
//
Log("Service Registration faild, Invalid Configuration ...");
XException.InvalidConfiguration.Throw();
}
//
source.AddSingleton(configuration);
Log("Service Configuration, Registered ...");
}
/// <summary>
/// Register Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXBotService( public static void AddXBotService(
this IServiceCollection services, this IServiceCollection services,
IConfiguration configuration,
XRepositoryType repositoryType, XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped ServiceLifetime lifeTime = ServiceLifetime.Scoped
) )
{ {
//
var config = configuration.GetXBotServiceConfiguration();
//
AddBotService( AddBotService(
contextType: null, contextType: null,
services: services, services: services,
lifeTime: lifeTime, lifeTime: lifeTime,
configuration: config,
repositoryType: repositoryType repositoryType: repositoryType
); );
} }
/// <summary> /// <summary>
/// Register XBotService with Context /// Register Service with Context ...
/// </summary> /// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
/// <typeparam name="TContext"></typeparam>
public static void AddXBotService<TContext>( public static void AddXBotService<TContext>(
this IServiceCollection services, this IServiceCollection services,
IConfiguration configuration,
XRepositoryType repositoryType, XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped ServiceLifetime lifeTime = ServiceLifetime.Scoped
) where TContext : XDbContext ) where TContext : XDbContext
{ {
//
var config = configuration.GetXBotServiceConfiguration();
//
AddBotService( AddBotService(
services: services, services: services,
lifeTime: lifeTime, lifeTime: lifeTime,
configuration: config,
contextType: typeof(TContext), contextType: typeof(TContext),
repositoryType: repositoryType repositoryType: repositoryType
); );
} }
/// <summary> /// <summary>
/// Use XBotService Middleware /// Register Service ...
/// </summary> /// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXBotService(
this IServiceCollection services,
XBotServiceConfiguration configuration,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
//
AddBotService(
contextType: null,
services: services,
lifeTime: lifeTime,
configuration: configuration,
repositoryType: repositoryType
);
}
/// <summary>
/// Register Service with Context ...
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
/// <typeparam name="TContext"></typeparam>
public static void AddXBotService<TContext>(
this IServiceCollection services,
XBotServiceConfiguration configuration,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
) where TContext : XDbContext
{
//
AddBotService(
services: services,
lifeTime: lifeTime,
configuration: configuration,
contextType: typeof(TContext),
repositoryType: repositoryType
);
}
/// <summary>
/// Use XBotService Middleware ...
/// </summary>
/// <param name="app"></param>
/// <param name="isDevelopmentEnvironment"></param>
public static void UseXBotService( public static void UseXBotService(
this IApplicationBuilder app, this IApplicationBuilder app,
bool isDevelopmentEnvironment = false bool isDevelopmentEnvironment = false
) )
{ {
// Using XBot Repository Descriptor //
if (!descriptor.IsNull()) #region Using XTag Hubs ...
//
var pushHelper = new XPushServiceHelper();
//
pushHelper.AddHub<XBotUserDtoHub>(XBotServiceConstants.XBotUserDtoHub);
pushHelper.AddHub<XBotUserEntityHub>(XBotServiceConstants.XBotUserEntityHub);
//
app.UseXPushService(pushHelper);
#endregion
//
// Using XBotUser Repository Descriptor ...
if (!botUserDescriptor.IsNull())
{ {
//
app.UseXRepository( app.UseXRepository(
descriptor: descriptor, descriptor: botUserDescriptor,
isDevelopmentEnvironment: isDevelopmentEnvironment isDevelopmentEnvironment: isDevelopmentEnvironment
); );
} }
@@ -72,7 +231,7 @@ namespace xBotService.DI
// //
#region Private ... #region Private ...
private static XRepositoryDescriptor descriptor = null; private static XRepositoryDescriptor botUserDescriptor = null;
private static string XLogTag = XBotServiceConstants.XBotServiceDILogTag; private static string XLogTag = XBotServiceConstants.XBotServiceDILogTag;
private static void Log(string message) private static void Log(string message)
@@ -82,6 +241,7 @@ namespace xBotService.DI
private static void AddBotService( private static void AddBotService(
IServiceCollection services, IServiceCollection services,
XBotServiceConfiguration configuration,
XRepositoryType repositoryType, XRepositoryType repositoryType,
Type contextType = null, Type contextType = null,
ServiceLifetime lifeTime = ServiceLifetime.Scoped ServiceLifetime lifeTime = ServiceLifetime.Scoped
@@ -109,6 +269,10 @@ namespace xBotService.DI
throw exception; throw exception;
} }
//
// Validate Configuration ...
services.AddXBotServiceConfiguration(configuration);
// //
// Validate Repository Type // Validate Repository Type
var isRepositoryTypeValid = var isRepositoryTypeValid =
@@ -116,43 +280,62 @@ namespace xBotService.DI
((repositoryType == XRepositoryType.Mongo || repositoryType == XRepositoryType.InMemory) && contextType.IsNull()); ((repositoryType == XRepositoryType.Mongo || repositoryType == XRepositoryType.InMemory) && contextType.IsNull());
if (!isRepositoryTypeValid) if (!isRepositoryTypeValid)
{ {
//
Log("Service Registration failed, Invalid Repository Type and Context Type ..."); Log("Service Registration failed, Invalid Repository Type and Context Type ...");
throw exception; throw exception;
} }
// //
// Make Instance of Repository Descriptor // Make Instance of Repository Descriptor ...
switch (repositoryType) switch (repositoryType)
{ {
//
case XRepositoryType.EF: case XRepositoryType.EF:
descriptor = typeof(XBotServiceHelper) botUserDescriptor = typeof(XBotServiceHelper)
.InvokeGenericMethod<XRepositoryDescriptor>( .InvokeGenericMethod<XRepositoryDescriptor>(
args: null, args: null,
runtimeType: contextType, runtimeType: contextType,
methodName: XBotServiceConstants.GetXBotUserEFRepositoryDescriptor methodName: XBotServiceConstants.GetXBotUserEFRepositoryDescriptor
); );
break; break;
//
case XRepositoryType.Mongo: case XRepositoryType.Mongo:
// descriptor = XBotServiceHelper.GetXBotUserMongoRepositoryDescriptor(); botUserDescriptor = XBotServiceHelper.GetXBotUserMongoRepositoryDescriptor();
Log("MongoDB support not implemented yet for XBotService.");
break; break;
//
case XRepositoryType.InMemory: case XRepositoryType.InMemory:
// descriptor = XBotServiceHelper.GetXBotUserInMemoryRepositoryDescriptor(); botUserDescriptor = XBotServiceHelper.GetXBotUserInMemoryRepositoryDescriptor();
Log("InMemory support not implemented yet for XBotService.");
break; break;
} }
// //
// Register XBotUser Repository Descriptor // Register XBotUser Repository Descriptor ...
if (!descriptor.IsNull()) services.AddXRepository(
{ lifeTime: lifeTime,
services.AddXRepository(lifeTime: lifeTime, descriptor: descriptor); descriptor: botUserDescriptor
} );
// //
// Register Dto Services // Register Dto Services ...
services.Add(new ServiceDescriptor(typeof(IXBotUserRepositoryService), typeof(XBotUserRepositoryService), lifeTime)); services.Add(
Log("XBotService Registration Succeed ..."); new ServiceDescriptor(typeof(IXBotUserServiceProvider), typeof(XBotUserServiceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXBotUserRepositoryService), typeof(XBotUserRepositoryService), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXBotUserRepositoryProvider), typeof(XBotUserRepositoryProvider), lifeTime)
);
//
services.Add(
new ServiceDescriptor(typeof(IXBotProvider), typeof(XBotProvider), lifeTime)
);
//
Log("Service Registration Succeed ...");
} }
#endregion #endregion
} }
+11
View File
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace xBotService.Interfaces
{
public interface IXBotProvider
{
}
}
@@ -0,0 +1,25 @@
using xPushService.Base;
using xDataService.Configuration;
using xBotService.Models.Entities;
using xIdentityService.Interfaces;
using Microsoft.AspNetCore.SignalR;
using xBotService.Interfaces.Entities;
namespace xBotService.Providers.Entities
{
public class XBotUserRepositoryProvider : XBaseEntityProvider<XBotUser, int, XBotUserEntityHub>, IXBotUserRepositoryProvider
{
public XBotUserRepositoryProvider(
IHubContext<XBotUserEntityHub> hub,
IXBotUserRepository repository,
XDataServiceConfiguration dataConfiguration,
IXIdentityProvider identityProvider = null
) : base(
hub,
repository,
dataConfiguration,
identityProvider
)
{ }
}
}
+9
View File
@@ -0,0 +1,9 @@
using xBotService.Interfaces;
namespace xBotService.Providers
{
public class XBotProvider : IXBotProvider
{
}
}