using System.Reflection; using Microsoft.Extensions.DependencyInjection; using Tiger.Communication.Messages.Interfaces; namespace Tiger.Utils; public static class DependencyInjectionExtensions { public static void RegisterMessageEvents(this IServiceCollection services) { // Get the assembly you are interested in (this could be any Assembly) var assembly = Assembly.GetExecutingAssembly(); // Get all types that implement IMessageEvent and are not abstract var messageEventTypes = assembly.GetTypes() .Where(t => t.GetInterfaces().Contains(typeof(IMessageEvent)) && !t.IsAbstract); // Register each type with AddSingleton foreach (var type in messageEventTypes) { services.AddSingleton(typeof(IMessageEvent), type); } } }