Skip to content

Commit fed5c05

Browse files
authored
Dev (#31)
* - if an endpoint or route group is mapped multiple times in its configuration method, configuration steps continue to run for each of them instead of the last one - code cleanup * - code cleanup * - add summary to di methods. * - add a discriminator value to configuration context for endpoints and routes mapped multiple times. A configuration step of any component cannot run twice with same self discriminator. * - add ComponentDiscriminator as scoped so it will be disposed after Map scope completes * - bugfix: prevent adding default request validation service to DI multiple times. * - add options to throw or not during service endpoint DI registration * - service endpoints are now registered to DI as keyed service with request type as key, removing the need for serviceendpointregistry and related checks/options * - code cleanup * - update deps * - added back check to ThrowOnDuplicateServiceEndpointRequest during DI registration * - bugfix: DI registration of service endpoints with streaming response * - refactor endpoint DI registration code for clarity * - code cleanup * - update test server configuration * - rename some options - update docs * - bump version
1 parent a6a674b commit fed5c05

24 files changed

+337
-174
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.3.0</Version>
21+
<Version>1.3.1</Version>
2222
</PropertyGroup>
2323
</Project>

docs/RequestValidation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal class GetBookById(ServiceDbContext db)
5555
```
5656

5757
## Disabling Default Request Validation
58-
Default request validation can be disabled during dependency injection by setting UseDefaultRequestValidation to false. This can be useful if you want to implement your own request validation logic or if you want to use a different validation library.
58+
You can opt out of default request validation by setting AddDefaultRequestValidatorService to false. This can be useful if you want to implement your own request validation logic or if you want to use a different validation library.
5959

6060
If you are using `ModEndpoints.Core` package:
6161
```csharp
@@ -64,7 +64,7 @@ var builder = WebApplication.CreateBuilder(args);
6464
// Add services to the container.
6565
builder.Services.AddModEndpointsCoreFromAssemblyContaining<MyEndpoint>(conf =>
6666
{
67-
conf.UseDefaultRequestValidation = false;
67+
conf.AddDefaultRequestValidatorService = false;
6868
});
6969

7070
// ... add other services
@@ -77,7 +77,7 @@ var builder = WebApplication.CreateBuilder(args);
7777
// Add services to the container.
7878
builder.Services.AddModEndpointsFromAssemblyContaining<MyEndpoint>(conf =>
7979
{
80-
conf.CoreOptions.UseDefaultRequestValidation = false;
80+
conf.CoreOptions.AddDefaultRequestValidatorService = false;
8181
});
8282

8383
// ... add other services

samples/ShowcaseWebApi/Program.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
var endpointFullName = endpoint.GetType().FullName;
2424
if (!string.IsNullOrWhiteSpace(endpointFullName))
2525
{
26-
builder.WithName(endpointFullName);
26+
var discriminator = configurationContext.Parameters.SelfDiscriminator;
27+
if (discriminator == 0)
28+
{
29+
builder.WithName(endpointFullName);
30+
}
31+
else
32+
{
33+
builder.WithName($"{endpointFullName}_{discriminator}");
34+
}
2735
}
2836
});
2937

src/ModEndpoints.Core/Constants.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
namespace ModEndpoints.Core;
22
internal static class Constants
33
{
4-
public const string RouteBuilderIsNullForEndpointMessage = "Route builder is null for {0} endpoint.";
5-
public const string RouteBuilderIsNullForRouteGroupMessage = "Route builder is null for {0} route group.";
6-
public const string RequiredServiceIsInvalidMessage = "Service resolved from dependency injection is invalid.";
4+
public const string RouteBuilderIsNullForEndpointMessage =
5+
"Route builder is null for {0} endpoint.";
6+
public const string RequiredServiceIsInvalidMessage =
7+
"Service resolved from dependency injection is invalid.";
8+
public const string MissingRouteGroupConfigurationMessage =
9+
"Missing route group configuration! Start configuring {0} route group by calling the MapGroup method of the builder.";
10+
public const string MissingRouteGroupConfigurationLogMessage =
11+
"Missing route group configuration! Start configuring {routeGroupType} route group by calling the MapGroup method of the builder.";
12+
public const string MissingEndpointConfigurationMessage =
13+
"Missing endpoint configuration! Start configuring {0} endpoint by calling one of the Map[HttpVerb] methods of the builder.";
14+
public const string MissingEndpointConfigurationLogMessage =
15+
"Missing endpoint configuration! Start configuring {endpointType} endpoint by calling one of the Map[HttpVerb] methods of the builder.";
16+
public const string ServiceEndpointAlreadyRegisteredMessage =
17+
"An endpoint for request type {0} is already registered.";
718
}

0 commit comments

Comments
 (0)