116 lines
3.7 KiB
C#
116 lines
3.7 KiB
C#
using System;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using xCommons.Extensions;
|
|
using xDataService.Interfaces;
|
|
using xDataService.Providers;
|
|
using xExceptions.Constants;
|
|
using xWebinarService.Interfaces;
|
|
using xWebinarService.Interfaces.Entities;
|
|
using xWebinarService.Models.Entities;
|
|
using xWebinarService.Providers;
|
|
|
|
namespace xWebinarService.DI
|
|
{
|
|
public static class XDIHelperExtension
|
|
{
|
|
/// <summary>
|
|
/// Register Module Provided Service on DI
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="config"></param>
|
|
public static void AddXWebinarService(
|
|
this IServiceCollection services,
|
|
ServiceLifetime lifeTime
|
|
)
|
|
{
|
|
//
|
|
AddWebinarService(
|
|
services,
|
|
lifeTime
|
|
);
|
|
}
|
|
|
|
//
|
|
#region Private ...
|
|
/// <summary>
|
|
/// a LogTag for XWebinarService ...
|
|
/// </summary>
|
|
private static string XLogTag = "XWebinarService";
|
|
|
|
/// <summary>
|
|
/// print a log in Console ...
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
private static void Log(string message)
|
|
{
|
|
Console.WriteLine($"{XLogTag} => {message}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register Push Service ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="lifeTime"></param>
|
|
private static void AddWebinarService(
|
|
IServiceCollection services,
|
|
ServiceLifetime lifeTime
|
|
)
|
|
{
|
|
//
|
|
var exception = XException.InvalidArgs.ToException(); ;
|
|
|
|
//
|
|
// Services ...
|
|
var isServicesExists = !services.IsNull();
|
|
if (!isServicesExists)
|
|
{
|
|
//
|
|
Log("AddWebinarService failed, services not provided ...");
|
|
throw exception;
|
|
}
|
|
|
|
//
|
|
// Lifetime ...
|
|
var isLifetimeExists = !lifeTime.IsNull();
|
|
if (!isLifetimeExists)
|
|
{
|
|
//
|
|
Log("AddWebinarService failed, lifetime not provided ...");
|
|
throw exception;
|
|
}
|
|
|
|
//
|
|
// Check String Repository Exists ...
|
|
var isWebinarRepositoryExists = !services
|
|
.GetRegisteredService<IXWebinarRepository>()
|
|
.IsNull() &&
|
|
!services.GetRegisteredService<IXWebinarSubscriberRepository>()
|
|
.IsNull();
|
|
if (!isWebinarRepositoryExists)
|
|
{
|
|
//
|
|
Log("AddWebinarService failed, IXWebinarRepository or IXWebinarSubscriberRepository not provided ...");
|
|
throw exception;
|
|
}
|
|
|
|
//
|
|
// Register Webinar Group In Memory Repository ...
|
|
services.AddSingleton<IXKeyGenerator<XWebinarGroupEntity, Guid>, XGuidKeyGenerator<XWebinarGroupEntity>>();
|
|
services.Add(new ServiceDescriptor(typeof(IXWebinarGroupStore), typeof(XWebinarGroupStore), ServiceLifetime.Singleton));
|
|
|
|
//
|
|
// 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("AddWebinarService Succeed ...");
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
} |