Skip to content

Commit

Permalink
Changed auto map method to be more generalized. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgernand authored Nov 17, 2023
1 parent 2b542de commit 8c422dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/AspNetCore.Endpoints/AspNetCore.Endpoints.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<RootNamespace>MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<IncludeSymbols>false</IncludeSymbols>
<Copyright>Copyright © 2023 Matthias Gernand. All rights reserved.</Copyright>
<Version>8.0.0</Version>
<AssemblyVersion>8.0.0</AssemblyVersion>
<FileVersion>8.0.0</FileVersion>
<Version>8.0.1</Version>
<AssemblyVersion>8.0.1</AssemblyVersion>
<FileVersion>8.0.1</FileVersion>
<Authors>Matthias Gernand</Authors>
<Description>A library that helps in building and configuring object-oriented minimal API endpoints.</Description>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
16 changes: 8 additions & 8 deletions src/AspNetCore.Endpoints/WebApplicationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static class WebApplicationExtensions
/// <summary>
/// Maps all <see cref="Endpoint"/> implementations from registered application parts.
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public static WebApplication MapEndpoints(this WebApplication app)
/// <param name="builder">The endpoint route builder to map the endpoints with.</param>
/// <returns>The endpoint route builder.</returns>
public static IEndpointRouteBuilder MapEndpoints(this IEndpointRouteBuilder builder)
{
Type endpointBaseType = typeof(EndpointBase);

Expand All @@ -40,28 +40,28 @@ public static WebApplication MapEndpoints(this WebApplication app)

foreach (IGrouping<EndpointGroup, EndpointBase> grouping in endpoints.GroupBy(x => x.Group))
{
RouteGroupBuilder groupEndpoints = app.MapGroup(grouping.Key);
RouteGroupBuilder groupEndpoints = builder.MapGroup(grouping.Key);
foreach (EndpointBase endpoint in grouping)
{
endpoint.Map(groupEndpoints);
}
}

return app;
return builder;
}

private static RouteGroupBuilder MapGroup(this WebApplication app, EndpointGroup group)
private static RouteGroupBuilder MapGroup(this IEndpointRouteBuilder builder, EndpointGroup group)
{
ArgumentNullException.ThrowIfNull(group);

EndpointsOptions options = app.Services.GetRequiredService<IOptions<EndpointsOptions>>().Value;
EndpointsOptions options = builder.ServiceProvider.GetRequiredService<IOptions<EndpointsOptions>>().Value;
string globalPrefix = options.EndpointsRoutePrefix?.Trim('/');

string prefix = string.IsNullOrWhiteSpace(globalPrefix)
? $"/{group.Name.ToLowerInvariant()}"
: $"/{globalPrefix}/{group.Name.ToLowerInvariant()}";

RouteGroupBuilder groupBuilder = app
RouteGroupBuilder groupBuilder = builder
.MapGroup(prefix)
.WithTags(group.Name);

Expand Down

0 comments on commit 8c422dd

Please sign in to comment.