Supercell.GUT/Supercell.GUT.Server/Protocol/Extensions/ServiceCollectionExtensions.cs

21 lines
626 B
C#
Raw Normal View History

using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Supercell.GUT.Server.Protocol.Attributes;
namespace Supercell.GUT.Server.Protocol.Extensions;
internal static class ServiceCollectionExtensions
{
public static IServiceCollection AddHandlers(this IServiceCollection services)
{
IEnumerable<Type> types = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.GetCustomAttribute<ServiceNodeAttribute>() != null);
foreach (Type type in types)
{
services.AddScoped(type);
}
return services;
}
}