0
0
RhSolutions-Api/RhSolutions.MLModifiers/MLModifiersRegistration.cs

25 lines
643 B
C#
Raw Normal View History

2024-01-26 15:50:41 +03:00
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<MLModifierKey>()?.Value ?? string.Empty;
}
}