From 69db707d6803ada3891e4e71b8660ad095392973 Mon Sep 17 00:00:00 2001 From: Serghei Cebotari Date: Thu, 8 Feb 2024 17:11:11 +0300 Subject: Rename Parser projects --- RhSolutions.Parsers/ParsersRegistration.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 RhSolutions.Parsers/ParsersRegistration.cs (limited to 'RhSolutions.Parsers/ParsersRegistration.cs') diff --git a/RhSolutions.Parsers/ParsersRegistration.cs b/RhSolutions.Parsers/ParsersRegistration.cs new file mode 100644 index 0000000..54f34be --- /dev/null +++ b/RhSolutions.Parsers/ParsersRegistration.cs @@ -0,0 +1,25 @@ +using Microsoft.Extensions.DependencyInjection; +using System.Reflection; + +namespace RhSolutions.Parsers; + +public static class ParsersRegistration +{ + public static void AddModifiers(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 = GetModifierKey(t); + services.AddKeyedTransient(typeof(IProductParser), key, t); + } + } + + private static string GetModifierKey(Type t) + { + return t.GetCustomAttribute()?.Value ?? string.Empty; + } +} \ No newline at end of file -- cgit v1.2.3