using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Luticate2.Auth.Utils.Business.ObjectConverter; using Luticate2.Auth.Utils.Business.ObjectConverterDescriptor; using Luticate2.Auth.Utils.Interfaces; using Microsoft.Extensions.DependencyInjection; namespace Luticate2.Auth.Utils.Business.Converters { public static class LuConvertersExtensions { public static void AddLuObjectConverterDescriptors(this IServiceCollection services) { var typeILuObjectConverterDescriptor = typeof(ILuObjectConverterDescriptor<,>); var typeILuObjectConverterDescriptorEnumerable = typeILuObjectConverterDescriptor.MakeGenericType(typeof(Enumerable), typeof(Enumerable)); services.AddSingleton(); services.AddSingleton(typeILuObjectConverterDescriptorEnumerable, typeof(LuObjectConverterDescriptorEnumerable)); } public static void AddLuObjectConverters(this IServiceCollection services) { var typeILuObjectConverter = typeof(ILuObjectConverter<,>); var listTypes = new [] { typeof(IEnumerable<>), typeof(ICollection<>), typeof(Collection<>), typeof(IList<>), typeof(List<>) }; var listImplemType = new Dictionary { {typeof(IEnumerable<>), typeof(LuObjectConverterList)}, {typeof(ICollection<>), typeof(LuObjectConverterCollection)}, {typeof(Collection<>), typeof(LuObjectConverterCollection)}, {typeof(IList<>), typeof(LuObjectConverterList)}, {typeof(List<>), typeof(LuObjectConverterList)} }; services.AddSingleton(); foreach (var typeFrom in listTypes) { foreach (var typeTo in listTypes) { services.AddSingleton(typeILuObjectConverter.MakeGenericType(typeFrom, typeTo), listImplemType[typeTo]); } } } public static void AddLuObjectConverterPoco(this IServiceCollection services) { services.AddSingleton, LuObjectConverterPoco>(); } } }