RSCG – MinimalApiBuilder
RSCG – MinimalApiBuilder
name | MinimalApiBuilder |
nuget | https://www.nuget.org/packages/MinimalApiBuilder/ |
link | https://github.com/JensDll/MinimalApiBuilder |
author |
Generate Minimal API from classes
This is how you can use MinimalApiBuilder .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net7.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.12" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> <PackageReference Include="MinimalApiBuilder" Version="1.3.3" /> </ItemGroup> <PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> </PropertyGroup> </Project>
The code that you will use is
using MinimalApiBuilder; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); //MinimalApiBuilder.DependencyInjection.AddMinimalApiBuilderEndpoints(builder.Services); builder.Services.AddMinimalApiBuilderEndpoints(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseAuthorization(); app.MapControllers(); app.MapGet<BasicEndpoint>("/hello"); app.Run();
using Microsoft.AspNetCore.Mvc; using MinimalApiBuilder; public partial class BasicEndpoint : MinimalApiBuilderEndpoint { private static string Handle([FromServices] BasicEndpoint endpoint) { return "Hello, World!"; } }
The code that is generated is
// <auto-generated> // This is a MinimalApiBuilder source generated file. // </auto-generated> #nullable enable namespace MinimalApiBuilder { public static class DependencyInjection { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("MinimalApiBuilder.Generator", "1.3.3.0")] public static global::Microsoft.Extensions.DependencyInjection.IServiceCollection AddMinimalApiBuilderEndpoints(this global::Microsoft.Extensions.DependencyInjection.IServiceCollection services) { global::Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddScoped<global::BasicEndpoint>(services); return services; } } }
// <auto-generated> // This is a MinimalApiBuilder source generated file. // </auto-generated> #nullable enable public partial class BasicEndpoint : global::MinimalApiBuilder.IEndpoint { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("MinimalApiBuilder.Generator", "1.3.3.0")] public static global::System.Delegate _auto_generated_Handler { get; } = Handle; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("MinimalApiBuilder.Generator", "1.3.3.0")] public static void _auto_generated_Configure(global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder builder) { } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("MinimalApiBuilder.Generator", "1.3.3.0")] public static void Configure(global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder builder) { } }
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/MinimalApiBuilder
Leave a Reply