using Microsoft.Extensions.DependencyInjection; using System.Reflection; namespace RhSolutions.MLModifiers; public static class MLModifiersRegistration { public static void AddModifiers(this IServiceCollection services) { var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => p.IsDefined(typeof(MLModifierKey), true)); foreach (Type t in types) { string key = GetModifierKey(t); services.AddKeyedTransient(typeof(IProductMLModifier), key, t); } } private static string GetModifierKey(Type t) { return t.GetCustomAttribute()?.Value ?? string.Empty; } }