mirror of
https://gitea.tendokyu.moe/Kayori/Medusa.net.git
synced 2026-09-25 15:57:56 +03:00
28 lines
1.0 KiB
C#
28 lines
1.0 KiB
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 entryAssembly = Assembly.GetEntryAssembly() ?? throw new InvalidOperationException("Could not find entry assembly.");
|
|
|
|
// Only register built-in server handlers here.
|
|
// Plugin handler types live in PluginSlot.HandlerTypes and are dispatched
|
|
// via PluginRegistry in HandlerService using the plugin's own mini-SP.
|
|
var builtInHandlers = entryAssembly.GetTypes()
|
|
.Where(t => t.GetInterfaces().Contains(typeof(IHandler)) ||
|
|
(t.IsSubclassOf(typeof(Handler<,>)) && !t.IsAbstract));
|
|
|
|
handlerService.Handlers.AddRange(builtInHandlers);
|
|
|
|
return app;
|
|
}
|
|
|
|
} |