summaryrefslogtreecommitdiff
path: root/RhSolutions.Parsers/ParsersRegistration.cs
diff options
context:
space:
mode:
Diffstat (limited to 'RhSolutions.Parsers/ParsersRegistration.cs')
-rw-r--r--RhSolutions.Parsers/ParsersRegistration.cs25
1 files changed, 25 insertions, 0 deletions
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<ParserKey>()?.Value ?? string.Empty;
+ }
+} \ No newline at end of file