WutheringWaves/GameServer/Extensions/ServiceCollectionExtensions.cs
2024-02-08 00:41:39 +03:00

20 lines
583 B
C#

using System.Reflection;
using GameServer.Handlers;
using Microsoft.Extensions.DependencyInjection;
namespace GameServer.Extensions;
internal static class ServiceCollectionExtensions
{
public static IServiceCollection AddHandlers(this IServiceCollection services)
{
IEnumerable<Type> handlerTypes = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.IsAssignableTo(typeof(MessageHandlerBase)) && !t.IsAbstract);
foreach (Type type in handlerTypes)
{
services.AddScoped(type);
}
return services;
}
}