-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDependencyInjection.cs
40 lines (35 loc) · 1.17 KB
/
DependencyInjection.cs
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
38
39
40
namespace Ordering.API;
using BuildingBlocks.Exceptions.Handler;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Configuration;
public static class DependencyInjection
{
public static IServiceCollection AddApiServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddCarter();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
services.AddExceptionHandler<CustomExceptionHandler>();
services.AddHealthChecks()
.AddSqlServer(configuration.GetConnectionString("Database")!);
return services;
}
public static WebApplication UseApiServices(this WebApplication app)
{
app.MapCarter();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseExceptionHandler(options => { });
app.UseHealthChecks("/health",
new HealthCheckOptions
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
return app;
}
}