Add String Service and Implement all of it's requirements as an xDashboard Package ...
This commit is contained in:
@@ -1,3 +1,83 @@
|
||||
namespace xStringService.DI {
|
||||
public static class XDIHelperExtension { }
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xExceptions.Constants;
|
||||
using xCommons.Extensions;
|
||||
using xStringService.Interfaces;
|
||||
using xStringService.Providers;
|
||||
|
||||
namespace xStringService.DI
|
||||
{
|
||||
public static class XDIHelperExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Register Module Provided Service on DI
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="config"></param>
|
||||
public static void AddXStringService(
|
||||
this IServiceCollection services,
|
||||
ServiceLifetime lifeTime
|
||||
)
|
||||
{
|
||||
AddStringService(
|
||||
services,
|
||||
lifeTime
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
/// <summary>
|
||||
/// a LogTag for XStringService ...
|
||||
/// </summary>
|
||||
private static string XLogTag = "XStringService";
|
||||
|
||||
/// <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 AddStringService(
|
||||
IServiceCollection services,
|
||||
ServiceLifetime lifeTime
|
||||
)
|
||||
{
|
||||
//
|
||||
var exception = XException.InvalidArgs.ToException(); ;
|
||||
|
||||
//
|
||||
// Services ...
|
||||
var isServicesExists = !services.IsNull();
|
||||
if (!isServicesExists)
|
||||
{
|
||||
//
|
||||
Log("AddStringService failed, services not provided ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Lifetime ...
|
||||
var isLifetimeExists = !lifeTime.IsNull();
|
||||
if (!isLifetimeExists)
|
||||
{
|
||||
//
|
||||
Log("AddStringService failed, lifetime not provided ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
services.Add(new ServiceDescriptor(typeof(IXStringProvider), typeof(XStringProvider), lifeTime));
|
||||
Log("AddStringService Succeed ...");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user