Files
reallife-gamemode/ReallifeGamemode.DataService/Logic/LogicBase.cs
2019-09-17 23:20:43 +02:00

36 lines
859 B
C#

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;
}
}
}