mirror of
https://gitea.tendokyu.moe/Kayori/Medusa.net.git
synced 2026-09-30 10:47:55 +03:00
24 lines
757 B
C#
24 lines
757 B
C#
using Server.Handlers;
|
|
using Server.Services;
|
|
using System.Reflection;
|
|
using Abstractions.Handlers;
|
|
using Abstractions.Services;
|
|
|
|
namespace Server.Extensions;
|
|
|
|
public static class ApplicationBuilderExtensions
|
|
{
|
|
public static IApplicationBuilder UseHandlers(this IApplicationBuilder app)
|
|
{
|
|
var handlerService = app.ApplicationServices.GetRequiredService<IHandlerService>();
|
|
|
|
var assembly = Assembly.GetEntryAssembly() ?? throw new InvalidOperationException("Could not find entry assembly.");
|
|
var types = assembly.GetTypes().Where(a => a.GetInterfaces().Contains(typeof(IHandler)) ||
|
|
(a.IsSubclassOf(typeof(Handler)) && !a.IsAbstract));
|
|
|
|
handlerService.Handlers.AddRange(types);
|
|
|
|
return app;
|
|
}
|
|
|
|
} |