implement Webinar and WebinarSubscriber Entity and Dto (s) and Data Requirements ...
This commit is contained in:
+178
-48
@@ -1,15 +1,20 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.Providers;
|
||||
using xCommons.Helpers;
|
||||
using xDataService.Constants;
|
||||
using xDataService.Db;
|
||||
using xDataService.DI;
|
||||
using xDataService.Models;
|
||||
using xExceptions.Constants;
|
||||
using xFileService.Interfaces;
|
||||
using xTagService.Interfaces;
|
||||
using xWebinarService.Interfaces;
|
||||
using xPushService.DI;
|
||||
using xPushService.Helpers;
|
||||
using xWebinarService.Helpers;
|
||||
using xWebinarService.Interfaces.Dtos;
|
||||
using xWebinarService.Interfaces.Entities;
|
||||
using xWebinarService.Models.Entities;
|
||||
using xWebinarService.Providers;
|
||||
using xWebinarService.Providers.Dtos;
|
||||
using xWebinarService.Providers.Entities;
|
||||
|
||||
namespace xWebinarService.DI
|
||||
{
|
||||
@@ -19,21 +24,99 @@ namespace xWebinarService.DI
|
||||
/// Register Service ...
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="repositoryType"></param>
|
||||
/// <param name="lifeTime"></param>
|
||||
public static void AddXWebinarService(
|
||||
this IServiceCollection services,
|
||||
ServiceLifetime lifeTime
|
||||
XRepositoryType repositoryType,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
)
|
||||
{
|
||||
AddWebinarService(
|
||||
contextType: null,
|
||||
services: services,
|
||||
lifeTime: lifeTime,
|
||||
repositoryType: repositoryType
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Service ...
|
||||
/// </summary>
|
||||
/// <typeparam name="TContext"></typeparam>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="repositoryType"></param>
|
||||
/// <param name="lifeTime"></param>
|
||||
public static void AddXWebinarService<TContext>(
|
||||
this IServiceCollection services,
|
||||
XRepositoryType repositoryType,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
)
|
||||
where TContext : XDbContext
|
||||
{
|
||||
AddWebinarService(
|
||||
services: services,
|
||||
lifeTime: lifeTime,
|
||||
contextType: typeof(TContext),
|
||||
repositoryType: repositoryType
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use XWebinarService Middleware ...
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="isDevelopmentEnvironment"></param>
|
||||
public static void UsexWebinarService(
|
||||
this IApplicationBuilder app,
|
||||
bool isDevelopmentEnvironment = false
|
||||
)
|
||||
{
|
||||
//
|
||||
AddWebinarService(
|
||||
services,
|
||||
lifeTime
|
||||
);
|
||||
#region Using XWebinar Hubs ...
|
||||
//
|
||||
var pushHelper = new XPushServiceHelper();
|
||||
|
||||
//
|
||||
pushHelper.AddHub<XWebinarDtoHub>("webinarDto");
|
||||
pushHelper.AddHub<XWebinarEntityHub>("webinarEntity");
|
||||
|
||||
//
|
||||
pushHelper.AddHub<XWebinarSubscriberDtoHub>("webinarSubscriberDto");
|
||||
pushHelper.AddHub<XWebinarSubscriberEntityHub>("webinarSubscriberEntity");
|
||||
|
||||
//
|
||||
app.UseXPushService(pushHelper);
|
||||
#endregion
|
||||
|
||||
//
|
||||
// Using XWebinar Repository Descriptor ...
|
||||
if (!webinarDescriptor.IsNull())
|
||||
{
|
||||
//
|
||||
app.UseXRepository(
|
||||
descriptor: webinarDescriptor,
|
||||
isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Using XWebinarSubscriber Repository Descriptor ...
|
||||
if (!webinarSubscriberDescriptor.IsNull())
|
||||
{
|
||||
//
|
||||
app.UseXRepository(
|
||||
descriptor: webinarSubscriberDescriptor,
|
||||
isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
private static XRepositoryDescriptor webinarDescriptor = null;
|
||||
private static XRepositoryDescriptor webinarSubscriberDescriptor = null;
|
||||
|
||||
/// <summary>
|
||||
/// a LogTag for Service ...
|
||||
/// </summary>
|
||||
@@ -52,10 +135,14 @@ namespace xWebinarService.DI
|
||||
/// Register Service ...
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="repositoryType"></param>
|
||||
/// <param name="contextType"></param>
|
||||
/// <param name="lifeTime"></param>
|
||||
private static void AddWebinarService(
|
||||
IServiceCollection services,
|
||||
ServiceLifetime lifeTime
|
||||
XRepositoryType repositoryType,
|
||||
Type contextType = null,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -67,7 +154,7 @@ namespace xWebinarService.DI
|
||||
if (!isServicesExists)
|
||||
{
|
||||
//
|
||||
Log("AddWebinarService failed, services not provided ...");
|
||||
Log("Service Registration failed, services not provided ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
@@ -77,60 +164,103 @@ namespace xWebinarService.DI
|
||||
if (!isLifetimeExists)
|
||||
{
|
||||
//
|
||||
Log("AddWebinarService failed, lifetime not provided ...");
|
||||
Log("Service Registration failed, lifetime not provided ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Dependencies Exists ...
|
||||
var isDependenciesPassed = !services
|
||||
.GetRegisteredService<IXWebinarSubscriberRepository>()
|
||||
.IsNull() &&
|
||||
!services.GetRegisteredService<IXTagProvider>().IsNull() &&
|
||||
!services.GetRegisteredService<IXFileProvider>().IsNull();
|
||||
if (!isDependenciesPassed)
|
||||
// Validate Repository Type ...
|
||||
var isRepositoryTypeValid =
|
||||
(repositoryType == XRepositoryType.EF &&
|
||||
!contextType.IsNull()) ||
|
||||
((repositoryType == XRepositoryType.Mongo ||
|
||||
repositoryType == XRepositoryType.InMemory) &&
|
||||
contextType.IsNull());
|
||||
if (!isRepositoryTypeValid)
|
||||
{
|
||||
//
|
||||
Log("AddFileService failed due Dependencies Issues, IXTagProvider, IXFileProvider, IXWebinarSubscriberRepository not provided ...");
|
||||
Log("Service Registration failed, Invalid Repository Type and Context Type ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Repository Exists ...
|
||||
var isRepositoryExists = !services
|
||||
.GetRegisteredService<IXWebinarRepository>()
|
||||
.IsNull();
|
||||
if (!isRepositoryExists)
|
||||
// Maske Instance of Repository Descriptor
|
||||
// Based on Provided Type ...
|
||||
switch (repositoryType)
|
||||
{
|
||||
//
|
||||
Log("AddWebinarService failed, IXWebinarRepository not provided ...");
|
||||
throw exception;
|
||||
case XRepositoryType.EF:
|
||||
//
|
||||
webinarDescriptor = typeof(XWebinarServiceHelper)
|
||||
.InvokeGenericMethod<XRepositoryDescriptor>(
|
||||
methodName: "GetXWebinarEFRepositoryDescriptor",
|
||||
runtimeType: contextType,
|
||||
args: null
|
||||
);
|
||||
|
||||
//
|
||||
webinarSubscriberDescriptor = typeof(XWebinarServiceHelper)
|
||||
.InvokeGenericMethod<XRepositoryDescriptor>(
|
||||
methodName: "GetXWebinarSubscriberEFRepositoryDescriptor",
|
||||
runtimeType: contextType,
|
||||
args: null
|
||||
);
|
||||
break;
|
||||
|
||||
//
|
||||
case XRepositoryType.Mongo:
|
||||
webinarDescriptor = XWebinarServiceHelper.GetXWebinarMongoRepositoryDescriptor();
|
||||
webinarSubscriberDescriptor = XWebinarServiceHelper.GetXWebinarSubscriberMongoRepositoryDescriptor();
|
||||
break;
|
||||
|
||||
//
|
||||
case XRepositoryType.InMemory:
|
||||
webinarDescriptor = XWebinarServiceHelper.GetXWebinarInMemoryRepositoryDescriptor();
|
||||
webinarSubscriberDescriptor = XWebinarServiceHelper.GetXWebinarSubscriberInMemoryRepositoryDescriptor();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Register Webinar Group In Memory Repository ...
|
||||
services.AddSingleton<IXKeyGenerator<XWebinarGroupEntity, Guid>, XGuidKeyGenerator<XWebinarGroupEntity>>();
|
||||
services.Add(new ServiceDescriptor(typeof(IXWebinarGroupStore), typeof(XWebinarGroupStore), ServiceLifetime.Singleton));
|
||||
// Register xWebinar Repository Descriptor ...
|
||||
services.AddXRepository(
|
||||
lifeTime: lifeTime,
|
||||
descriptor: webinarDescriptor
|
||||
);
|
||||
|
||||
services.AddXRepository(
|
||||
lifeTime: lifeTime,
|
||||
descriptor: webinarSubscriberDescriptor
|
||||
);
|
||||
|
||||
//
|
||||
// Register Resource Providers ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXWebinarTitleResourceProvider), typeof(XWebinarTitleResourceProvider), lifeTime));
|
||||
services.Add(new ServiceDescriptor(typeof(IXWebinarDescriptionResourceProvider), typeof(XWebinarDescriptionResourceProvider), lifeTime));
|
||||
// Register Dto Services ...
|
||||
services.Add(
|
||||
new ServiceDescriptor(typeof(IXWebinarServiceProvider), typeof(XWebinarServiceProvider), lifeTime)
|
||||
);
|
||||
services.Add(
|
||||
new ServiceDescriptor(typeof(IXWebinarRepositoryService), typeof(XWebinarRepositoryService), lifeTime)
|
||||
);
|
||||
services.Add(
|
||||
new ServiceDescriptor(typeof(IXWebinarRepositoryProvider), typeof(XWebinarRepositoryProvider), lifeTime)
|
||||
);
|
||||
|
||||
services.Add(
|
||||
new ServiceDescriptor(typeof(IXWebinarSubscriberServiceProvider), typeof(XWebinarSubscriberServiceProvider), lifeTime)
|
||||
);
|
||||
services.Add(
|
||||
new ServiceDescriptor(typeof(IXWebinarSubscriberRepositoryService), typeof(XWebinarSubscriberRepositoryService), lifeTime)
|
||||
);
|
||||
services.Add(
|
||||
new ServiceDescriptor(typeof(IXWebinarSubscriberRepositoryProvider), typeof(XWebinarSubscriberRepositoryProvider), lifeTime)
|
||||
);
|
||||
|
||||
//
|
||||
// Register Webinar Tag Provider ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXWebinarTagProvider), typeof(XWebinarTagProvider), lifeTime));
|
||||
// services.Add(
|
||||
// new ServiceDescriptor(typeof(IXWebinarProvider), typeof(XWebinarProvider), lifeTime)
|
||||
// );
|
||||
|
||||
//
|
||||
// Register Webinar File Provider ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXWebinarFileProvider), typeof(XWebinarFileProvider), lifeTime));
|
||||
|
||||
//
|
||||
// Register Main Provider ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXWebinarProvider), typeof(XWebinarProvider), lifeTime));
|
||||
|
||||
//
|
||||
Log("AddWebinarService Succeed ...");
|
||||
Log("Service Regitration Succeed ...");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user