using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using ReallifeGamemode.Database.Models; namespace ReallifeGamemode.DataService.Logic { public abstract class LogicBase { protected readonly DatabaseContext dbContext; public LogicBase(DatabaseContext dbContext) { this.dbContext = dbContext; } } public static class ServiceCollectionExtensions { public static IServiceCollection AddLogic(this IServiceCollection services) { Type[] types = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(LogicBase)) && !t.IsAbstract).ToArray(); foreach(Type type in types) { services = services.AddScoped(type); } return services; } } }