diff --git a/src/SharedKernel/Extensions/ControllerExtensions.cs b/src/SharedKernel/Extensions/ControllerExtensions.cs index e0e4271..1303a55 100644 --- a/src/SharedKernel/Extensions/ControllerExtensions.cs +++ b/src/SharedKernel/Extensions/ControllerExtensions.cs @@ -1,6 +1,10 @@ using System.Reflection; +using System.Text.RegularExpressions; +using Humanizer; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.Extensions.DependencyInjection; +using Microsoft.OpenApi.Models; namespace SharedKernel.Extensions; @@ -8,7 +12,7 @@ public static class ControllerExtensions { public static WebApplicationBuilder AddControllers(this WebApplicationBuilder builder, Assembly[] assemblies) { - var mvcBuilder = builder.Services.AddControllers(); + var mvcBuilder = builder.Services.AddControllers(options => options.Conventions.Add(new ToLowerNamingConvention())); foreach (var assembly in assemblies) { mvcBuilder.AddApplicationPart(assembly); @@ -16,4 +20,17 @@ public static WebApplicationBuilder AddControllers(this WebApplicationBuilder bu return builder; } +} + +public class ToLowerNamingConvention : IControllerModelConvention +{ + public void Apply(ControllerModel controller) + { + controller.ControllerName = controller.ControllerName.Kebaberize(); + + foreach (var action in controller.Actions) + { + action.ActionName = action.ActionName.Kebaberize(); + } + } } \ No newline at end of file diff --git a/src/SharedKernel/SharedKernel.csproj b/src/SharedKernel/SharedKernel.csproj index 098fabe..3219848 100644 --- a/src/SharedKernel/SharedKernel.csproj +++ b/src/SharedKernel/SharedKernel.csproj @@ -8,13 +8,13 @@ Readme.md Pandatech MIT - 1.0.11 + 1.0.12 Pandatech.SharedKernel Pandatech Shared Kernel Library Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document. https://github.com/PandaTechAM/be-lib-sharedkernel - OpenApi update + Controller naming to kebab