0
0
RhSolutions-Api/RhSolutions.Parsers/ParsersRegistration.cs
Serghei Cebotari c13f4ddda1
All checks were successful
Test and release / test (push) Successful in 3m1s
Test and release / release-image (push) Successful in 3m40s
Rename service add method
2024-02-09 16:48:42 +03:00

25 lines
624 B
C#

using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
namespace RhSolutions.Parsers;
public static class ParsersRegistration
{
public static void AddProductParsers(this IServiceCollection services)
{
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => p.IsDefined(typeof(ParserKey), true));
foreach (Type t in types)
{
string key = GetParserKey(t);
services.AddKeyedTransient(typeof(IProductParser), key, t);
}
}
private static string GetParserKey(Type t)
{
return t.GetCustomAttribute<ParserKey>()?.Value ?? string.Empty;
}
}