Skip to content

Commit f8c22c9

Browse files
authored
Merge pull request #13 from PandaTechAM/development
dependency fix, multiplatform support, documentation enhancement
2 parents 99864ec + d42d9cd commit f8c22c9

File tree

4 files changed

+145
-134
lines changed

4 files changed

+145
-134
lines changed

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Pandatech.FluentMinimalApiMapper
2+
3+
A lightweight helper for auto-discovering and registering Minimal API endpoints across assemblies. Define `IEndpoint`,
4+
call two methods in `Program.cs`, and every endpoint in your project is wired up automatically.
5+
6+
Inspired by Carter's routing concept but stripped to the essentials — no dependencies beyond ASP.NET Core itself.
7+
8+
Targets **`net8.0`**, **`net9.0`**, and **`net10.0`**.
9+
10+
---
11+
12+
## Table of Contents
13+
14+
1. [Features](#features)
15+
2. [Installation](#installation)
16+
3. [Getting Started](#getting-started)
17+
4. [Multiple Assemblies](#multiple-assemblies)
18+
5. [Route Grouping](#route-grouping)
19+
20+
---
21+
22+
## Features
23+
24+
- Auto-discovers all `IEndpoint` implementations at startup via reflection — once, not per request
25+
- Works across multiple assemblies for modular monolith and vertical slice layouts
26+
- `TryAddEnumerable` registration prevents duplicates if the same assembly is scanned more than once
27+
- No configuration required, no base classes, no attributes
28+
29+
---
30+
31+
## Installation
32+
33+
```bash
34+
dotnet add package Pandatech.FluentMinimalApiMapper
35+
```
36+
37+
---
38+
39+
## Getting Started
40+
41+
### 1. Define an endpoint
42+
43+
```csharp
44+
public class ProductEndpoints : IEndpoint
45+
{
46+
public void AddRoutes(IEndpointRouteBuilder app)
47+
{
48+
app.MapGet("/products", () => Results.Ok());
49+
app.MapPost("/products", () => Results.Created());
50+
}
51+
}
52+
```
53+
54+
### 2. Register and map in Program.cs
55+
56+
```csharp
57+
builder.AddMinimalApis(); // scans entry assembly by default
58+
59+
var app = builder.Build();
60+
61+
app.MapMinimalApis();
62+
app.Run();
63+
```
64+
65+
That's all. Every `IEndpoint` implementation in the entry assembly is discovered and registered automatically.
66+
67+
---
68+
69+
## Multiple Assemblies
70+
71+
Pass any number of assemblies explicitly — useful in modular monolith setups where each module lives in its own project:
72+
73+
```csharp
74+
builder.AddMinimalApis(
75+
typeof(ProductEndpoints).Assembly,
76+
typeof(OrderEndpoints).Assembly);
77+
```
78+
79+
---
80+
81+
## Route Grouping
82+
83+
Pass a `RouteGroupBuilder` to `MapMinimalApis` to apply shared configuration (prefix, auth policy, filters, etc.)
84+
to all discovered endpoints at once:
85+
86+
```csharp
87+
var api = app.MapGroup("/api/v1").RequireAuthorization();
88+
app.MapMinimalApis(api);
89+
```
90+
91+
Or apply multiple group configurations selectively by calling `MapMinimalApis` more than once with different groups,
92+
scanning different assemblies each time.
93+
94+
---
95+
96+
## License
97+
98+
MIT

Readme.md

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,60 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net10.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
4+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
65
<Nullable>enable</Nullable>
7-
<PackageIcon>pandatech.png</PackageIcon>
8-
<PackageReadmeFile>Readme.md</PackageReadmeFile>
9-
<Authors>Pandatech</Authors>
10-
<Copyright>MIT</Copyright>
11-
<Version>3.0.1</Version>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
8+
<IsPackable>true</IsPackable>
9+
1210
<PackageId>Pandatech.FluentMinimalApiMapper</PackageId>
13-
<Title>FluentMinimalApiMapper: Effortless Endpoint Integration</Title>
14-
<PackageTags>Pandatech, library, MinimalAPI, AutoMapping, FluentAPI, EndpointRegistration</PackageTags>
15-
<Description>FluentMinimalApiMapper redefines the simplicity of minimal API development, offering an intuitive and automated approach to endpoint mapping. With a focus on streamlined integration, this NuGet package by PandaTech is the perfect tool for developers looking to enhance the efficiency and readability of their modular applications. Dive into the seamless world of API development with FluentMinimalApiMapper, where every route is a journey simplified.</Description>
11+
<Authors>Pandatech</Authors>
12+
<Description>Lightweight auto-discovery and mapping of Minimal API endpoints across assemblies. Define IEndpoint, call AddMinimalApis and MapMinimalApis — no configuration required.</Description>
13+
<PackageTags>minimal-api;minimal-apis;endpoint-mapping;auto-discovery;modular;clean-architecture</PackageTags>
14+
15+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
16+
<RepositoryType>git</RepositoryType>
1617
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-fluent-minimal-api-mapper</RepositoryUrl>
17-
<PackageReleaseNotes>nuget updates</PackageReleaseNotes>
18+
<PackageProjectUrl>https://github.com/PandaTechAM/be-lib-fluent-minimal-api-mapper</PackageProjectUrl>
19+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1820

19-
<!-- Never run analyzers as part of compilation (local, CI, dotnet build/test/publish) -->
20-
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
21+
<PackageIcon>pandatech.png</PackageIcon>
22+
<PackageReadmeFile>README.md</PackageReadmeFile>
2123

22-
<!-- Keep background/live analysis in the IDE -->
23-
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis>
24+
<Version>4.0.0</Version>
25+
<PackageReleaseNotes>Multi-target net8.0/net9.0/net10.0, switched to FrameworkReference</PackageReleaseNotes>
26+
27+
<!-- Build quality -->
28+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
29+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2430

25-
<!-- Optional: ensure code-style analyzers don't run during build either -->
31+
<!-- Source/symbols -->
32+
<IncludeSymbols>true</IncludeSymbols>
33+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
34+
<ContinuousIntegrationBuild Condition="'$(CI)' == 'true'">true</ContinuousIntegrationBuild>
35+
36+
<!-- Analyzer behavior -->
37+
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
38+
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis>
2639
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
2740
</PropertyGroup>
2841

2942
<ItemGroup>
3043
<None Include="..\..\pandatech.png" Pack="true" PackagePath="\"/>
31-
<None Include="..\..\Readme.md" Pack="true" PackagePath="\"/>
44+
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
45+
</ItemGroup>
46+
47+
<ItemGroup>
48+
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
3249
</ItemGroup>
3350

51+
<!-- Analyzers -->
3452
<ItemGroup>
35-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
36-
<PackageReference Include="Pandatech.Analyzers" Version="2.1.0" />
37-
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.18.0.131500">
53+
<PackageReference Include="Pandatech.Analyzers" Version="[2.1.0]" PrivateAssets="all"/>
54+
<PackageReference Include="SonarAnalyzer.CSharp" Version="[10.18.0.131500]">
3855
<PrivateAssets>all</PrivateAssets>
3956
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4057
</PackageReference>
4158
</ItemGroup>
4259

43-
</Project>
60+
</Project>

src/FluentMinimalApiMapper/WebAppExtensions.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,29 @@ public static class WebAppExtensions
1010
{
1111
public static WebApplicationBuilder AddMinimalApis(this WebApplicationBuilder builder, params Assembly[] assemblies)
1212
{
13-
if (assemblies.Length == 0) return builder;
13+
if (assemblies.Length == 0)
14+
assemblies = [Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()];
1415

1516
var candidates = assemblies
1617
.SelectMany(a => a.DefinedTypes)
17-
.Where(t => t is { IsAbstract: false, IsInterface: false } && t.IsAssignableTo(typeof(IEndpoint)))
18-
.Distinct()
19-
.ToArray();
18+
.Where(t => t is { IsAbstract: false, IsInterface: false } &&
19+
t.IsAssignableTo(typeof(IEndpoint)))
20+
.Distinct();
2021

2122
foreach (var t in candidates)
2223
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient(typeof(IEndpoint), t));
2324

2425
return builder;
2526
}
2627

27-
public static WebApplicationBuilder AddMinimalApis(this WebApplicationBuilder builder)
28-
{
29-
var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
30-
return builder.AddMinimalApis(assembly);
31-
}
32-
3328
public static WebApplication MapMinimalApis(this WebApplication app, RouteGroupBuilder? routeGroupBuilder = null)
3429
{
35-
var endpoints = app.Services
36-
.GetRequiredService<IEnumerable<IEndpoint>>();
30+
var endpoints = app.Services.GetRequiredService<IEnumerable<IEndpoint>>();
3731

38-
IEndpointRouteBuilder builder =
39-
routeGroupBuilder is null ? app : routeGroupBuilder;
32+
IEndpointRouteBuilder routeBuilder = routeGroupBuilder is null ? app : routeGroupBuilder;
4033

41-
foreach (var endpoint in endpoints) endpoint.AddRoutes(builder);
34+
foreach (var endpoint in endpoints)
35+
endpoint.AddRoutes(routeBuilder);
4236

4337
return app;
4438
}

0 commit comments

Comments
 (0)