DataService hinzugefügt
This commit is contained in:
35
ReallifeGamemode.DataService/Logic/LogicBase.cs
Normal file
35
ReallifeGamemode.DataService/Logic/LogicBase.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user