Files
2025-10-27 17:39:18 -04:00

30 lines
1.7 KiB
C#

using Microsoft.AspNetCore.Builder;
namespace Prefab.Endpoints;
/// <summary>
/// Provides extension methods for configuring endpoint names with module-based naming conventions in ASP.NET Core
/// routing.
/// </summary>
/// <remarks>These methods help standardize endpoint naming by prefixing endpoint names with a module name
/// inferred from a specified type. This can improve discoverability and organization of endpoints, especially in
/// modular applications. The extensions are intended for use with ASP.NET Core's routing infrastructure and are
/// typically called when configuring endpoints in minimal APIs or similar scenarios.</remarks>
public static class Extensions
{
/// <summary>
/// Applies an endpoint name that combines the module name inferred from <typeparamref name="T"/> with the type name.
/// </summary>
/// <typeparam name="T">A type that belongs to the module the endpoint lives in, typically the endpoint class itself.</typeparam>
public static RouteHandlerBuilder WithModuleName<T>(this RouteHandlerBuilder builder)
=> builder.WithModuleName<T>(typeof(T).Name);
/// <summary>
/// Applies an endpoint name that combines the module name inferred from <typeparamref name="T"/> with the provided endpoint name.
/// </summary>
/// <typeparam name="T">A type that belongs to the module the endpoint lives in, typically the endpoint class itself.</typeparam>
/// <param name="endpointName">The base endpoint name that will be prefixed with the module name.</param>
public static RouteHandlerBuilder WithModuleName<T>(this RouteHandlerBuilder builder, string endpointName)
=> builder.WithName(EndpointName.For<T>(endpointName));
}