using System; using Microsoft.Extensions.DependencyInjection; using xCommons.Extensions; using xExceptions.Constants; using xFileService.Interfaces; using xFileService.Interfaces.Entities; using xFileService.Providers; using xStorageService.Interfaces; namespace xFileService.DI { public static class XDIHelperExtension { /// /// Register Service ... /// /// /// public static void AddXFileService( this IServiceCollection services, ServiceLifetime lifeTime ) { // AddFileService( services, lifeTime ); } // #region Private ... /// /// a LogTag for Service ... /// private static string XLogTag = "XFileService"; /// /// print a log in Console ... /// /// private static void Log(string message) { Console.WriteLine($"{XLogTag} => {message}"); } /// /// Register Service ... /// /// /// 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 Dependencies Exists ... var isDependenciesPassed = !services .GetRegisteredService() .IsNull(); if (!isDependenciesPassed) { // Log("AddFileService failed due Dependencies Issues, IXStorageProvider not provided ..."); throw exception; } // // Check Repository Exists ... var isRepositoryExists = !services .GetRegisteredService() .IsNull(); if (!isRepositoryExists) { // Log("AddFileService failed, IXFileRepository not provided ..."); throw exception; } // // Register Main Provider ... services.Add(new ServiceDescriptor(typeof(IXFileProvider), typeof(XFileProvider), lifeTime)); // Log("AddFileService Succeed ..."); } #endregion } }