DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs
Reginald Cherenfant Jasmin 5ad4478670 Merge Conflict resolution
2023-12-07 02:28:57 -05:00

73 lines
2.8 KiB
C#

using DamageAssesment.Api.Responses.Db;
using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.Responses.Services;
using DamageAssesment.Api.Responses.Providers;
using Microsoft.EntityFrameworkCore;
using Polly;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
const int maxApiCallRetries = 3;
const int intervalToRetry = 2; //2 seconds
const int maxRetryForCircuitBraker = 5;
const int intervalForCircuitBraker = 5; //5 seconds
// Add services to the container.
builder.Services.AddControllers();
// CORS setup to allow requests from any origin.
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddScoped<ISurveysResponse, SurveyResponsesProvider>();
builder.Services.AddScoped<IAnswerServiceProvider, AnswerServiceProvider>();
builder.Services.AddScoped<ILocationServiceProvider, LocationServiceProvider>();
builder.Services.AddScoped<IRegionServiceProvider, RegionServiceProvider>();
builder.Services.AddScoped<IQuestionServiceProvider, QuestionServiceProvider>();
builder.Services.AddScoped<IEmployeeServiceProvider, EmployeeServiceProvider>();
builder.Services.AddScoped<IAttachmentServiceProvider, AttachmentServiceProvider>();
builder.Services.AddScoped<ISurveyServiceProvider, SurveyServiceProvider>();
builder.Services.AddScoped<IExcelExportService, ExcelExportService>();
builder.Services.AddHttpClient<IHttpUtil, HttpUtil>().
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker)));
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddEndpointsApiExplorer();
//builder.Services.AddSwaggerGen();
// Add Swagger/OpenAPI documentation support.
builder.Services.AddSwaggerGen(c =>
{
// Include XML comments from your assembly
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
builder.Services.AddDbContext<SurveyResponseDbContext>(option =>
{
option.UseSqlServer("ResponsesConnection");
});
builder.Services.AddCors(p => p.AddPolicy("DamageAppCorsPolicy", build => {
build.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCors("DamageAppCorsPolicy");
app.UseAuthorization();
app.MapControllers();
app.Run();