add Push Notification Related to XBotUser entitiy, and some missing Providers and also Registration in DI Extensions ...
This commit is contained in:
@@ -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
@@ -1,70 +1,229 @@
|
||||
using System;
|
||||
using xDataService.Db;
|
||||
using xDataService.DI;
|
||||
using xPushService.DI;
|
||||
using xCommons.Helpers;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Models;
|
||||
using xPushService.Helpers;
|
||||
using xExceptions.Constants;
|
||||
using xBotService.Constants;
|
||||
using xBotService.Providers;
|
||||
using xDataService.Constants;
|
||||
using xBotService.Interfaces;
|
||||
using XBotUserService.Helpers;
|
||||
using xHttpService.Interfaces;
|
||||
using xBotService.Configuration;
|
||||
using xBotService.Providers.Dtos;
|
||||
using xBotService.Interfaces.Dtos;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using xBotService.Providers.Entities;
|
||||
using xBotService.Interfaces.Entities;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using xBotService.Interfaces.Entities.Dtos;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ConfigurationNodeNames = xBotService.Constants.ConfigurationNodeNames;
|
||||
|
||||
namespace xBotService.DI
|
||||
{
|
||||
public static class XDIHelperExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Register XBotService
|
||||
/// Retrieve Bot Service Configuration ...
|
||||
/// </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(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration,
|
||||
XRepositoryType repositoryType,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
)
|
||||
{
|
||||
//
|
||||
var config = configuration.GetXBotServiceConfiguration();
|
||||
|
||||
//
|
||||
AddBotService(
|
||||
contextType: null,
|
||||
services: services,
|
||||
lifeTime: lifeTime,
|
||||
configuration: config,
|
||||
repositoryType: repositoryType
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register XBotService with Context
|
||||
/// 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,
|
||||
IConfiguration configuration,
|
||||
XRepositoryType repositoryType,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
) where TContext : XDbContext
|
||||
{
|
||||
//
|
||||
var config = configuration.GetXBotServiceConfiguration();
|
||||
|
||||
//
|
||||
AddBotService(
|
||||
services: services,
|
||||
lifeTime: lifeTime,
|
||||
configuration: config,
|
||||
contextType: typeof(TContext),
|
||||
repositoryType: repositoryType
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use XBotService Middleware
|
||||
/// Register Service ...
|
||||
/// </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(
|
||||
this IApplicationBuilder app,
|
||||
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(
|
||||
descriptor: descriptor,
|
||||
descriptor: botUserDescriptor,
|
||||
isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||
);
|
||||
}
|
||||
@@ -72,7 +231,7 @@ namespace xBotService.DI
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
private static XRepositoryDescriptor descriptor = null;
|
||||
private static XRepositoryDescriptor botUserDescriptor = null;
|
||||
private static string XLogTag = XBotServiceConstants.XBotServiceDILogTag;
|
||||
|
||||
private static void Log(string message)
|
||||
@@ -82,6 +241,7 @@ namespace xBotService.DI
|
||||
|
||||
private static void AddBotService(
|
||||
IServiceCollection services,
|
||||
XBotServiceConfiguration configuration,
|
||||
XRepositoryType repositoryType,
|
||||
Type contextType = null,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
@@ -109,6 +269,10 @@ namespace xBotService.DI
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Configuration ...
|
||||
services.AddXBotServiceConfiguration(configuration);
|
||||
|
||||
//
|
||||
// Validate Repository Type
|
||||
var isRepositoryTypeValid =
|
||||
@@ -116,43 +280,62 @@ namespace xBotService.DI
|
||||
((repositoryType == XRepositoryType.Mongo || repositoryType == XRepositoryType.InMemory) && contextType.IsNull());
|
||||
if (!isRepositoryTypeValid)
|
||||
{
|
||||
//
|
||||
Log("Service Registration failed, Invalid Repository Type and Context Type ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Make Instance of Repository Descriptor
|
||||
// Make Instance of Repository Descriptor ...
|
||||
switch (repositoryType)
|
||||
{
|
||||
//
|
||||
case XRepositoryType.EF:
|
||||
descriptor = typeof(XBotServiceHelper)
|
||||
botUserDescriptor = typeof(XBotServiceHelper)
|
||||
.InvokeGenericMethod<XRepositoryDescriptor>(
|
||||
args: null,
|
||||
runtimeType: contextType,
|
||||
methodName: XBotServiceConstants.GetXBotUserEFRepositoryDescriptor
|
||||
);
|
||||
break;
|
||||
|
||||
//
|
||||
case XRepositoryType.Mongo:
|
||||
// descriptor = XBotServiceHelper.GetXBotUserMongoRepositoryDescriptor();
|
||||
Log("MongoDB support not implemented yet for XBotService.");
|
||||
botUserDescriptor = XBotServiceHelper.GetXBotUserMongoRepositoryDescriptor();
|
||||
break;
|
||||
|
||||
//
|
||||
case XRepositoryType.InMemory:
|
||||
// descriptor = XBotServiceHelper.GetXBotUserInMemoryRepositoryDescriptor();
|
||||
Log("InMemory support not implemented yet for XBotService.");
|
||||
botUserDescriptor = XBotServiceHelper.GetXBotUserInMemoryRepositoryDescriptor();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Register XBotUser Repository Descriptor
|
||||
if (!descriptor.IsNull())
|
||||
{
|
||||
services.AddXRepository(lifeTime: lifeTime, descriptor: descriptor);
|
||||
}
|
||||
// Register XBotUser Repository Descriptor ...
|
||||
services.AddXRepository(
|
||||
lifeTime: lifeTime,
|
||||
descriptor: botUserDescriptor
|
||||
);
|
||||
|
||||
//
|
||||
// Register Dto Services
|
||||
services.Add(new ServiceDescriptor(typeof(IXBotUserRepositoryService), typeof(XBotUserRepositoryService), lifeTime));
|
||||
Log("XBotService Registration Succeed ...");
|
||||
// Register Dto Services ...
|
||||
services.Add(
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using xBotService.Interfaces;
|
||||
|
||||
namespace xBotService.Providers
|
||||
{
|
||||
public class XBotProvider : IXBotProvider
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user