100 lines
3.1 KiB
C#
100 lines
3.1 KiB
C#
using System;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using xCommons.Configurations;
|
|
using xCommons.Extensions;
|
|
using xExceptions.Constants;
|
|
using xStringService.Interfaces.Dtos;
|
|
using xTermsAndConditionsService.Interfaces;
|
|
using xTermsAndConditionsService.Providers;
|
|
|
|
namespace xTermsAndConditionsService.DI
|
|
{
|
|
public static class XDIHelperExtension
|
|
{
|
|
/// <summary>
|
|
/// Register TermsConditions Provider ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="lifeTime"></param>
|
|
public static void AddXTermsConditionsService(
|
|
this IServiceCollection services,
|
|
ServiceLifetime lifeTime = ServiceLifetime.Transient
|
|
)
|
|
{
|
|
//
|
|
AddTermsConditionsService(
|
|
services: services,
|
|
lifeTime: lifeTime
|
|
);
|
|
}
|
|
|
|
//
|
|
#region Private ...
|
|
/// <summary>
|
|
/// a LogTag for Service ...
|
|
/// </summary>
|
|
private static string XLogTag = "XTermsConditionsService";
|
|
|
|
/// <summary>
|
|
/// print a log in Console ...
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
private static void Log(string message)
|
|
{
|
|
Console.WriteLine($"{XLogTag} => {message}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Terms and Conditions Provider Service ...
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="lifeTime"></param>
|
|
private static void AddTermsConditionsService(
|
|
IServiceCollection services,
|
|
ServiceLifetime lifeTime = ServiceLifetime.Transient
|
|
)
|
|
{
|
|
//
|
|
var exception = XException.InvalidArgs.ToException(); ;
|
|
|
|
//
|
|
// Services ...
|
|
var isServicesExists = !services.IsNull();
|
|
if (!isServicesExists)
|
|
{
|
|
//
|
|
Log("AddTermsConditions failed, services not provided ...");
|
|
throw exception;
|
|
}
|
|
|
|
//
|
|
// Lifetime ...
|
|
var isLifetimeExists = !lifeTime.IsNull();
|
|
if (!isLifetimeExists)
|
|
{
|
|
//
|
|
Log("AddTermsConditions failed, lifetime not provided ...");
|
|
throw exception;
|
|
}
|
|
|
|
//
|
|
// Check Dependencies Exists ...
|
|
var isDependenciesPassed = !services
|
|
.GetRegisteredService<XAppConfiguration>()
|
|
.IsNull() &&
|
|
!services.GetRegisteredService<IXStringRepositoryService>()
|
|
.IsNull();
|
|
if (!isDependenciesPassed)
|
|
{
|
|
//
|
|
Log("AddTermsConditions failed due Dependencies Issues, IXStringRepository or XAppConfiguration not provided ...");
|
|
throw exception;
|
|
}
|
|
|
|
//
|
|
// Register Resource Providers ...
|
|
services.Add(new ServiceDescriptor(typeof(IXTermsAndComditionsProvider), typeof(XTermsAndComditionsProvider), lifeTime));
|
|
}
|
|
#endregion
|
|
}
|
|
} |