Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/SharedKernel/Extensions/ControllerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
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;

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);
}

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();
}
}
}
4 changes: 2 additions & 2 deletions src/SharedKernel/SharedKernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>Pandatech</Authors>
<Copyright>MIT</Copyright>
<Version>1.0.11</Version>
<Version>1.0.12</Version>
<PackageId>Pandatech.SharedKernel</PackageId>
<Title>Pandatech Shared Kernel Library</Title>
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
<Description>Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-sharedkernel</RepositoryUrl>
<PackageReleaseNotes>OpenApi update</PackageReleaseNotes>
<PackageReleaseNotes>Controller naming to kebab</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down