Implement XFile Provider ...
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xFileService.Interfaces;
|
||||
using xFileService.Providers;
|
||||
|
||||
namespace xFileService.DI
|
||||
{
|
||||
public static class XDIHelperExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Register Module Provided Service on DI
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="config"></param>
|
||||
public static void AddXFileService(
|
||||
this IServiceCollection services,
|
||||
ServiceLifetime lifeTime
|
||||
)
|
||||
{
|
||||
//
|
||||
AddFileService(
|
||||
services,
|
||||
lifeTime
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
/// <summary>
|
||||
/// a LogTag for Service ...
|
||||
/// </summary>
|
||||
private static string XLogTag = "XFileService";
|
||||
|
||||
/// <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 AddFileService(
|
||||
IServiceCollection services,
|
||||
ServiceLifetime lifeTime
|
||||
)
|
||||
{
|
||||
//
|
||||
var exception = XException.InvalidArgs.ToException(); ;
|
||||
|
||||
//
|
||||
// Services ...
|
||||
var isServicesExists = !services.IsNull();
|
||||
if (!isServicesExists)
|
||||
{
|
||||
//
|
||||
Log("AddFileService failed, services not provided ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Lifetime ...
|
||||
var isLifetimeExists = !lifeTime.IsNull();
|
||||
if (!isLifetimeExists)
|
||||
{
|
||||
//
|
||||
Log("AddFileService failed, lifetime not provided ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Check String Repository Exists ...
|
||||
var isRepositoryExists = !services
|
||||
.GetRegisteredService<IXTagRepository>()
|
||||
.IsNull();
|
||||
if (!isRepositoryExists)
|
||||
{
|
||||
//
|
||||
Log("AddFileService failed, IXTagRepository not provided ...");
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Register Main Provider ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXFileProvider), typeof(XFileProvider), lifeTime));
|
||||
|
||||
//
|
||||
Log("AddFileService Succeed ...");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal class IXTagRepository
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user