Skip to content

Commit a6a674b

Browse files
authored
Dev (#30)
* - seperate lifetime configuration setting for endpoints and route group configurators * - **breaking change** major overhaul of configuration and registration * - continue configuration overhaul * - add set accessor to ConfigurationPropertyBag * - refactor service provider name in configuration context * - code cleanup * - rename various classes because naming things is hard * - move configuration override func parameters out of settings * - configurator interfaces no longer implement corresponding configuration setting interfaces - remove configuratoion setting interfaces and replace with configuration parameter classes * - prune unused code * - prune unused code * - replace abstract override configuration properties with methods in both endpoint and route group configurators * - update docs * - update docs * - rename OverrideConfiguration methods to PostConfigure * - bump version
1 parent f7304a1 commit a6a674b

File tree

84 files changed

+574
-466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+574
-466
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1919
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
2020

21-
<Version>1.2.0</Version>
21+
<Version>1.3.0</Version>
2222
</PropertyGroup>
2323
</Project>

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
Each endpoint must implement two virtual methods:
5555

56-
1. **Configure**: Invoked during application startup to define the route and HTTP method for an endpoint. It begins with methods like `MapGet`, `MapPost`, etc., to specify the route pattern. The returned `RouteHandlerBuilder` from the Map[HttpVerb] method can then be used for further endpoint customization.
56+
1. **Configure**: Invoked during application startup to define the route and HTTP method for an endpoint. It begins with calling input parameter `builder`'s methods like `MapGet`, `MapPost`, etc., to specify the route pattern. The returned `RouteHandlerBuilder` from the Map[HttpVerb] method can then be used for further endpoint customization.
5757

5858
2. **HandleAsync**: Contains the logic to handle incoming requests. Called after the request is validated (if applicable).
5959

@@ -126,10 +126,10 @@ internal class HelloWorld
126126
: MinimalEndpoint<HelloWorldRequest, IResult>
127127
{
128128
protected override void Configure(
129-
IServiceProvider serviceProvider,
130-
IRouteGroupConfigurator? parentRouteGroup)
129+
EndpointConfigurationBuilder builder,
130+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
131131
{
132-
MapGet("MinimalEndpoints/HelloWorld/{Name}")
132+
builder.MapGet("MinimalEndpoints/HelloWorld/{Name}")
133133
.Produces<string>();
134134
}
135135

@@ -164,10 +164,10 @@ internal class GetWeatherForecast : MinimalEndpoint<WeatherForecast[]>
164164
];
165165

166166
protected override void Configure(
167-
IServiceProvider serviceProvider,
168-
IRouteGroupConfigurator? parentRouteGroup)
167+
EndpointConfigurationBuilder builder,
168+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
169169
{
170-
MapGet("/weatherforecast")
170+
builder.MapGet("/weatherforecast")
171171
.WithName("GetWeatherForecast")
172172
.WithTags("WeatherForecastWebApi");
173173
}
@@ -203,10 +203,10 @@ internal class ListBooks(ServiceDbContext db)
203203
: WebResultEndpointWithEmptyRequest<ListBooksResponse>
204204
{
205205
protected override void Configure(
206-
IServiceProvider serviceProvider,
207-
IRouteGroupConfigurator? parentRouteGroup)
206+
EndpointConfigurationBuilder builder,
207+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
208208
{
209-
MapGet("/books")
209+
builder.MapGet("/books")
210210
.Produces<ListBooksResponse>();
211211
}
212212

docs/DisablingComponents.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ internal class DisabledCustomerFeature
1111
: MinimalEndpoint<IResult>
1212
{
1313
protected override void Configure(
14-
IServiceProvider serviceProvider,
15-
IRouteGroupConfigurator? parentRouteGroup)
14+
EndpointConfigurationBuilder builder,
15+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
1616
{
17-
MapGet("/disabled/");
17+
builder.MapGet("/disabled/");
1818
}
1919

2020
protected override Task<IResult> HandleAsync(

docs/HandlingFiles.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ internal class UploadBook
2222
: WebResultEndpoint<UploadBookRequest, UploadBookResponse>
2323
{
2424
protected override void Configure(
25-
IServiceProvider serviceProvider,
26-
IRouteGroupConfigurator? parentRouteGroup)
25+
EndpointConfigurationBuilder builder,
26+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
2727
{
28-
MapPost("/upload/{Title}")
28+
builder.MapPost("/upload/{Title}")
2929
.DisableAntiforgery()
3030
.Produces<UploadBookResponse>();
3131
}
@@ -69,10 +69,10 @@ internal class DownloadCustomers(ServiceDbContext db)
6969
: MinimalEndpoint<DownloadCustomersRequest, IResult>
7070
{
7171
protected override void Configure(
72-
IServiceProvider serviceProvider,
73-
IRouteGroupConfigurator? parentRouteGroup)
72+
EndpointConfigurationBuilder builder,
73+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
7474
{
75-
MapPost("/download/{FileName}");
75+
builder.MapPost("/download/{FileName}");
7676
}
7777

7878
protected override async Task<IResult> HandleAsync(

docs/IAsyncEnumerableResponse.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ internal class ListCustomers(ServiceDbContext db)
1313
: MinimalEndpointWithStreamingResponse<ListCustomersResponse>
1414
{
1515
protected override void Configure(
16-
IServiceProvider serviceProvider,
17-
IRouteGroupConfigurator? parentRouteGroup)
16+
EndpointConfigurationBuilder builder,
17+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
1818
{
19-
MapGet("/");
19+
builder.MapGet("/");
2020
}
2121

2222
protected override IAsyncEnumerable<ListCustomersResponse> HandleAsync(CancellationToken ct)

docs/ParameterBinding.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ internal class UpdateBook(ServiceDbContext db)
2626
: WebResultEndpoint<UpdateBookRequest, UpdateBookResponse>
2727
{
2828
protected override void Configure(
29-
IServiceProvider serviceProvider,
30-
IRouteGroupConfigurator? parentRouteGroup)
29+
EndpointConfigurationBuilder builder,
30+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
3131
{
32-
MapPut("/books/{Id}")
32+
builder.MapPut("/books/{Id}")
3333
.Produces<UpdateBookResponse>();
3434
}
3535

@@ -81,10 +81,10 @@ internal class UploadBook
8181
: WebResultEndpoint<UploadBookRequest, UploadBookResponse>
8282
{
8383
protected override void Configure(
84-
IServiceProvider serviceProvider,
85-
IRouteGroupConfigurator? parentRouteGroup)
84+
EndpointConfigurationBuilder builder,
85+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
8686
{
87-
MapPost("/books/upload/{Title}")
87+
builder.MapPost("/books/upload/{Title}")
8888
.DisableAntiforgery()
8989
.Produces<UploadBookResponse>();
9090
}

docs/RequestValidation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ internal class GetBookById(ServiceDbContext db)
2828
: WebResultEndpoint<GetBookByIdRequest, GetBookByIdResponse>
2929
{
3030
protected override void Configure(
31-
IServiceProvider serviceProvider,
32-
IRouteGroupConfigurator? parentRouteGroup)
31+
EndpointConfigurationBuilder builder,
32+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
3333
{
34-
MapGet("/{Id}")
34+
builder.MapGet("/{Id}")
3535
.Produces<GetBookByIdResponse>();
3636
}
3737

docs/RouteGroups.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
By default, all endpoints are mapped under root route group. It is possible to define route groups similar to using 'MapGroup' extension method used to map Minimal APIs under a group. Since endpoints are configured by endpoint basis in the 'Configure' method of each endpoint, the approach is a little different than configuring a Minimal API. But route group configuration still utilize Minimal API route groups and can be decorated by any extension method of RouteGroupBuilder. Route groups are also subject to auto discovery and registration, similar to endpoints.
44

55
- [Create a route group implementation](../samples/ShowcaseWebApi/Features/FeaturesRouteGroup.cs) by inheriting RouteGroupConfigurator and implementing 'Configure' method,
6-
- Configuration of each route group implementation starts with calling MapGroup method with a route pattern prefix. The return of 'MapGroup' method, a RouteGroupBuilder instance, can be used to further customize the route group like any Minimal API route group.
6+
- Configuration of each route group implementation starts with calling input parameter `builder`'s MapGroup method with a route pattern prefix. The return of 'MapGroup' method, a RouteGroupBuilder instance, can be used to further customize the route group like any Minimal API route group.
77
- Apply MapToGroup attribute to either other [route group](../samples/ShowcaseWebApi/Features/Books/Configuration/BooksV1RouteGroup.cs) or [endpoint](../samples/ShowcaseWebApi/Features/Books/CreateBook.cs) classes that will be mapped under created route group. Use type of the new route group implementation as GroupType parameter to the attribute.
88

99
Following sample creates a parent route group (FeaturesRouteGroup), a child route group under it (BooksV1RouteGroup) and maps an endpoint (CreateBook) to child route group. Group configuration methods used for this particular sample are all part of Minimal APIs ecosystem and are under [Asp.Versioning](https://github.com/dotnet/aspnet-api-versioning).
@@ -12,27 +12,27 @@ Following sample creates a parent route group (FeaturesRouteGroup), a child rout
1212
internal class FeaturesRouteGroup : RouteGroupConfigurator
1313
{
1414
protected override void Configure(
15-
IServiceProvider serviceProvider,
16-
IRouteGroupConfigurator? parentRouteGroup)
15+
RouteGroupConfigurationBuilder builder,
16+
ConfigurationContext<RouteGroupConfigurationParameters> configurationContext)
1717
{
18-
var builder = MapGroup("/api/v{version:apiVersion}");
19-
var apiVersionSet = builder.NewApiVersionSet()
18+
var groupBuilder = builder.MapGroup("/api/v{version:apiVersion}");
19+
var apiVersionSet = groupBuilder.NewApiVersionSet()
2020
.HasApiVersion(new ApiVersion(1))
2121
.HasApiVersion(new ApiVersion(2))
2222
.ReportApiVersions()
2323
.Build();
24-
builder.WithApiVersionSet(apiVersionSet);
24+
groupBuilder.WithApiVersionSet(apiVersionSet);
2525
}
2626
}
2727

2828
[MapToGroup<FeaturesRouteGroup>()]
2929
internal class BooksV1RouteGroup : RouteGroupConfigurator
3030
{
3131
protected override void Configure(
32-
IServiceProvider serviceProvider,
33-
IRouteGroupConfigurator? parentRouteGroup)
32+
RouteGroupConfigurationBuilder builder,
33+
ConfigurationContext<RouteGroupConfigurationParameters> configurationContext)
3434
{
35-
MapGroup("/books")
35+
builder.MapGroup("/books")
3636
.MapToApiVersion(1)
3737
.WithTags("/BooksV1");
3838
}
@@ -43,10 +43,10 @@ internal class CreateBook(ServiceDbContext db, ILocationStore location)
4343
: WebResultEndpoint<CreateBookRequest, CreateBookResponse>
4444
{
4545
protected override void Configure(
46-
IServiceProvider serviceProvider,
47-
IRouteGroupConfigurator? parentRouteGroup)
46+
EndpointConfigurationBuilder builder,
47+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
4848
{
49-
MapPost("/")
49+
builder.MapPost("/")
5050
.Produces<CreateBookResponse>(StatusCodes.Status201Created);
5151
}
5252
protected override async Task<Result<CreateBookResponse>> HandleAsync(

docs/WebResultEndpointResponseMapping.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ internal class GetBookById(ServiceDbContext db)
1111
: WebResultEndpoint<GetBookByIdRequest, GetBookByIdResponse>
1212
{
1313
protected override void Configure(
14-
IServiceProvider serviceProvider,
15-
IRouteGroupConfigurator? parentRouteGroup)
14+
EndpointConfigurationBuilder builder,
15+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
1616
{
17-
MapGet("/{Id}")
17+
builder.MapGet("/{Id}")
1818
.Produces<GetBookByIdResponse>();
1919
}
2020

@@ -51,10 +51,10 @@ internal class GetBookById
5151
: WebResultEndpoint<GetBookByIdRequest, GetBookByIdResponse>
5252
{
5353
protected override void Configure(
54-
IServiceProvider serviceProvider,
55-
IRouteGroupConfigurator? parentRouteGroup)
54+
EndpointConfigurationBuilder builder,
55+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
5656
{
57-
MapGet("/{Id}")
57+
builder.MapGet("/{Id}")
5858
.Produces<GetBookByIdResponse>();
5959
}
6060

samples/BenchmarkWebApi/Features/MinimalEndpoints/BasicTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ internal class BasicTest
66
: MinimalEndpoint<IResult>
77
{
88
protected override void Configure(
9-
IServiceProvider serviceProvider,
10-
IRouteGroupConfigurator? parentRouteGroup)
9+
EndpointConfigurationBuilder builder,
10+
ConfigurationContext<EndpointConfigurationParameters> configurationContext)
1111
{
12-
MapGet("/MinimalEndpoints/BasicTest")
12+
builder.MapGet("/MinimalEndpoints/BasicTest")
1313
.Produces<string>();
1414
}
1515

0 commit comments

Comments
 (0)