Files
duplicati/Duplicati/WebserverCore/Extensions/WebApplicationExtensions.cs
T

37 lines
1.1 KiB
C#
Raw Normal View History

2024-03-15 16:51:01 +01:00
using System.Reflection;
using Duplicati.WebserverCore.Abstractions;
using Duplicati.WebserverCore.Middlewares;
2024-03-15 16:51:01 +01:00
namespace Duplicati.WebserverCore.Extensions;
public static class WebApplicationExtensions
{
public static WebApplication AddEndpoints(this WebApplication application)
{
return AddV1(application);
}
private static WebApplication AddV1(WebApplication application)
{
2024-06-07 15:56:43 +02:00
var mapperInterfaceType = typeof(IEndpointV1);
2024-03-15 16:51:01 +01:00
var endpoints =
typeof(WebApplicationExtensions).Assembly.DefinedTypes
.Where(t => t.ImplementedInterfaces.Contains(mapperInterfaceType))
.ToArray();
if (endpoints.Length == 0)
{
return application;
}
foreach (var endpoint in endpoints)
{
var group = application.MapGroup("/api/v1")
.AddEndpointFilter<LanguageFilter>();
2024-06-07 15:56:43 +02:00
var methodMap = endpoint.GetMethod(nameof(IEndpointV1.Map), BindingFlags.Static | BindingFlags.Public);
2024-03-15 16:51:01 +01:00
methodMap!.Invoke(null, [group]);
}
return application;
}
}