Skip to main content

SkinnyControllersCommon by Ignat Andrei

NuGet / site data​

Nuget GitHub last commit GitHub Repo stars

Details​

Info​

info

Original Readme​

note

SkinnyControllersGenerator

SkinnyControllers generates controller action for each field of your controller

How to install SkinnyControllers in a .NET Core 5 WebAPI / MVC application Step 1:

Install https://www.nuget.org/packages/SkinnyControllersGenerator/

Step 2:

Install https://www.nuget.org/packages/SkinnyControllersCommon/

Step 3:

Add a field to your action either via DI, either directly

    [ApiController]
[Route("[controller]/[action]")]
public partial class WeatherForecastController : ControllerBase
{

private readonly RepositoryWF repository;

public WeatherForecastController(RepositoryWF repository)
{
this.repository = repository;
//or make
//this.repository=new RepositoryWF();
}

Step 4:

Add partial declaration and decorate your controller with

[AutoActions(template = TemplateIndicator.AllPost,FieldsName =new[] *, ExcludeFields =new[]_logger)] [ApiController] [Route("[controller]/[action]")] public partial class WeatherForecastController : ControllerBase

You can choose your template from

  1. All Post
  2. Get - if not arguments, POST else
  3. Rest action

You can add your template in 2 ways: //if custom template , hte name must end in controller.txt

  1. [AutoActions(template = TemplateIndicator.CustomTemplateFile, FieldsName = new[] * ,CustomTemplateFileName = "Controllers\CustomTemplate1.controller.txt")]

  2. For creating new generic templates, please PR to https://github.com/ignatandrei/SkinnyControllersGenerator

That's all!

Usual problems:

  1. error CS0260: Missing partial modifier on declaration of type

Answer:

Did you put partial on the controller declaration ?

public partial class

More Roslyn Source Code Generators

You can find more RSCG with examples at Roslyn Source Code Generators

About​

note

Automatically add controllers actions for any class injected in constructor

How to use​

Example ( source csproj, source files )​

This is the CSharp Project that references SkinnyControllersCommon

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SkinnyControllersCommon" Version="2023.5.14.2055" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>

Generated Files​

Those are taken from $(BaseIntermediateOutputPath)\GX

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// SkinnyControllersGenerator:
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.CodeDom.Compiler;
using System.Runtime.CompilerServices;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace SkinnyControllersDemo.Controllers {
[GeneratedCode("SkinnyControllersGenerator", "")]
[CompilerGenerated]
partial class WeatherForecastController{
/*[HttpGet()]
public int id(){
System.Diagnostics.Debugger.Break();
return 1;
} */



[HttpGet]
public System.Collections.Generic.IEnumerable<SkinnyControllersDemo.WeatherForecast> Get (){
//System.Diagnostics.Debugger.Break();

return

weather.Get();

}


[HttpPost]
public System.Threading.Tasks.Task<int> MultiplyBy2 (int nr){
//System.Diagnostics.Debugger.Break();

return

weather.MultiplyBy2(nr);

}


}
}

Useful​

Download Example (.NET C# )​

Share SkinnyControllersCommon​

https://ignatandrei.github.io/RSCG_Examples/v2/docs/SkinnyControllersCommon

In the same category (API) - 9 other generators​

immediate.apis​

Microsoft.Extensions.Configuration.Binder​

MinimalApiBuilder​

MinimalApis.Discovery​

MinimalHelpers.Routing.Analyzers​

RDG​

Refit​

RSCG_WebAPIExports​

SafeRouting​