-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppExtensions.cs
More file actions
38 lines (33 loc) · 1.31 KB
/
AppExtensions.cs
File metadata and controls
38 lines (33 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using NSwag.AspNetCore;
using TalentManagementAPI.WebApi.Middlewares;
namespace TalentManagementAPI.WebApi.Extensions
{
// Static class containing extension methods for IApplicationBuilder
public static class AppExtensions
{
// Extension method to configure and use Swagger for API documentation
public static void UseSwaggerExtension(this IApplicationBuilder app)
{
// Serve the generated OpenAPI document and Swagger UI via NSwag.
app.UseOpenApi(settings =>
{
settings.Path = "/swagger/{documentName}/swagger.json";
});
app.UseSwaggerUi(settings =>
{
settings.Path = "/swagger";
settings.DocumentPath = "/swagger/{documentName}/swagger.json";
});
}
// Extension method to add custom middleware for error handling
public static void UseErrorHandlingMiddleware(this IApplicationBuilder app)
{
// Uses the ErrorHandlerMiddleware to process exceptions and generate appropriate responses
app.UseMiddleware<ErrorHandlerMiddleware>();
}
public static void UseRequestTimingMiddleware(this IApplicationBuilder app)
{
app.UseMiddleware<RequestTimingMiddleware>();
}
}
}