namespace LaaProductionWeb.Services { using LaaProductionWeb.Services.Interfaces; using Microsoft.Extensions.DependencyInjection; using System.Linq; public static class ServicesExtensions { public static IServiceCollection AddTransientServices(this IServiceCollection services) { var transient = typeof(ITransient); var assemblyServices = transient .Assembly .GetTypes() .Where(x => !x.IsAbstract && transient.IsAssignableFrom(x)); foreach (var service in assemblyServices) { var interfaces = service .GetInterfaces() .Where(x => x != transient); if (!interfaces.Any()) { services.AddTransient(service); continue; } foreach (var @interface in interfaces) { services.AddTransient(@interface, service); } } return services; } } }