25 lines
643 B
C#
25 lines
643 B
C#
|
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;
|
||
|
}
|
||
|
}
|