using System;
using Microsoft.Extensions.DependencyInjection;
using xCommons.Extensions;
using xExceptions.Constants;
using xWebinarService.Interfaces;
using xWebinarService.Interfaces.Entities;
using xWebinarService.Providers;
namespace xWebinarService.DI {
public static class XDIHelperExtension
{
///
/// Register Module Provided Service on DI
///
///
///
public static void AddXWebinarService(
this IServiceCollection services,
ServiceLifetime lifeTime
)
{
//
AddWebinarService(
services,
lifeTime
);
}
//
#region Private ...
///
/// a LogTag for XWebinarService ...
///
private static string XLogTag = "XWebinarService";
///
/// print a log in Console ...
///
///
private static void Log(string message)
{
Console.WriteLine($"{XLogTag} => {message}");
}
///
/// Register Push Service ...
///
///
///
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()
.IsNull() &&
!services.GetRegisteredService()
.IsNull();
if (!isWebinarRepositoryExists)
{
//
Log("AddWebinarService failed, IXWebinarRepository or IXWebinarSubscriberRepository 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("AddWebinarService Succeed ...");
}
#endregion
}
}