Files
monorepo/LCU.API.Operations.IncentiveAPI/LCU.API.Internal.Operations.IncentiveApi/Program.cs
T
2026-03-17 09:53:09 -05:00

554 lines
28 KiB
C#

using System.IO;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.FeatureManagement;
using Microsoft.OpenApi.Models;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Converters;
using LCU.API.Internal.Operations.IncentiveApi.Configuration;
using LCU.API.Internal.Operations.IncentiveApi.DataAccess;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApi.Services;
using LCU.API.Internal.Operations.IncentiveApi.Services.Action;
using LCU.API.Internal.Operations.IncentiveApi.Services.Allied;
using LCU.API.Internal.Operations.IncentiveApi.Authorization;
using LCU.API.Internal.Operations.IncentiveApi.Consumers;
using LCU.API.Internal.Operations.IncentiveApi.Services.AutoDecision;
using LCU.API.Internal.Operations.IncentiveApi.Services.Dayforce;
using LCU.API.Internal.Operations.IncentiveApi.Services.DispersalStrategy;
using LCU.API.Internal.Operations.IncentiveApi.Services.DuplicateDetection;
using LCU.API.Internal.Operations.IncentiveApi.Services.ExternalActivity;
using LCU.API.Internal.Operations.IncentiveApi.Services.MicroApiServices;
using LCU.API.Internal.Operations.IncentiveApi.Services.Payout;
using LCU.API.Internal.Operations.IncentiveApi.Services.QueueServices;
using LCU.API.Internal.Operations.IncentiveApi.Services.Rules;
using LCU.API.Internal.Operations.IncentiveApi.Services.Temenos;
using LCU.API.Internal.Operations.IncentiveApi.Services.Reporting;
using LCU.API.Internal.Operations.IncentiveApi.Services.DnaActivityServices;
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.Library.Internal.LcuHttpClient;
using IAuthorizationService = LCU.API.Internal.Operations.IncentiveApi.Services.IAuthorizationService;
using LCU.Library.Internal.LcuMassTransit;
using LCU.Library.Internal.LcuMassTransitModels;
using LCU.Library.Internal.Logging.Models;
using LCU.Library.Internal.Logging;
using LCU.Library.Internal.Logging.Middleware;
using LCU.Library.Internal.Status;
using LCU.API.Internal.Operations.IncentiveApi.Services.IncentiveProcesses;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
using LCU.Library.Internal.Configuration;
using LCU.Library.Internal.LCUServiceFactory;
using LCU.API.Internal.Operations.IncentiveApi.DnaActivityServices;
using LCU.API.Internal.Operations.IncentiveApi.HostedServices;
using LCU.API.Internal.Operations.IncentiveApi.Services.NightlyIncentiveProcesses;
using LCU.API.Internal.Operations.IncentiveApi.Services.NightlyDecisionServices;
using LCU.Library.Internal.Security;
using MassTransit;
string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
ApiConfiguration _apiConfiguration;
var builder = BuildBuilder(args);
BuildServicesAndConfigurations(builder);
BuildAppAndRun(builder);
WebApplicationBuilder BuildBuilder(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("/app/config/mapped-appsettings/primary.json", true, true);
builder.Configuration.AddJsonFile("/vault/secrets/incentive-manager-api-mass-queue-password.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/incentive-manager-api-mass-queue-username.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/incentive-manager-api-dayforce-username.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/incentive-manager-api-dayforce-password.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/incentive-manager-api-seq-api-key.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/incentive-manager-api-db-connection.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/incentive-manager-api-azure-valid-audience.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/incentive-manager-api-azure-client-id.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile("/vault/secrets/incentive-manager-api-azure-tenant-id.json", optional: true, reloadOnChange: true);
builder.Host.UseSerilog();
return builder;
}
void BuildServicesAndConfigurations(WebApplicationBuilder builder)
{
var services = builder.Services;
var configuration = builder.Configuration;
_apiConfiguration = configuration.Bind<ApiConfiguration>(services, "Primary");
configuration.Bind<FileOperationsApiConfiguration>(services);
configuration.Bind<EmailRecipientsConfiguration>(services);
configuration.Bind<NotificationApiConfiguration>(services);
configuration.Bind<ReportConfiguration>(services);
configuration.Bind<CoreApiWrapperConfiguration>(services);
configuration.Bind<DayForceConfiguration>(services);
var servicesFactoryConfiguration = configuration.Bind<ServicesFactoryConfiguration>(services);
var loggerConfiguration = new LoggingConfiguration(_apiConfiguration.AppName,
_apiConfiguration.SeqKey,
_apiConfiguration.SeqUrl);
var lcuLogging = new LcuLogging(loggerConfiguration);
lcuLogging.UseLcuLogging();
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddAzureAdBearer(options => configuration.Bind("AzureActiveDirectory", options));
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = _apiConfiguration.AppName,
Version = "v1"
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Id = "Bearer",
Type = ReferenceType.SecurityScheme
}
},
new List<string>()
}
});
c.AddSecurityDefinition("Bearer",
new OpenApiSecurityScheme
{
Description = "JWT Authorization header using the Bearer scheme.",
Type = SecuritySchemeType.Http,
Scheme = "bearer"
});
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
services.AddFeatureManagement(configuration.GetSection("Primary:FeatureGates"));
services.AddScoped<ICurrentUserService, CurrentUserService>();
services.AddTransient<IDateTime, DateTimeService>();
services.AddSingleton<IAuthorizationPolicyProvider, PermissionPolicyProvider>();
services.AddScoped<IAuthorizationHandler, PermissionAuthorizationHandler>();
services.AddCors(options =>
{
options.AddPolicy(MyAllowSpecificOrigins,
builder =>
{
builder.WithOrigins(
_apiConfiguration.CorsAllowedOrigins
).AllowAnyHeader().AllowAnyMethod().AllowCredentials();
});
});
services.AddScoped<IApplicationDbContext>(provider => provider.GetService<ApplicationDbContext>());
var sqlConnectionConfiguration = configuration.Bind<SqlConnectionConfiguration>(services);
services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlServer
(
sqlConnectionConfiguration.ConnectionString,
sql => sql.EnableRetryOnFailure(sqlConnectionConfiguration.MaxRetryCount, sqlConnectionConfiguration.MaxRetryDelay, null)
);
});
var connectionConfiguration = MassTransitConfigurationSetUp.AddConnectionConfiguration(ref services, configuration);
var receiveEndpointConfigurations = new ReceiveEndpointConfigurations
{
ImportCreditCardSalesEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "ImportCreditCardSalesEndpoint"),
ImportIndirectVehicleSalesEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "ImportIndirectVehicleSalesEndpoint"),
ReportingProcessEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "ReportingProcessEndpoint"),
GoalDispersalProcessEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "GoalDispersalProcessEndpoint"),
PayoutIncentiveProcessEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "PayoutIncentiveProcessEndpoint"),
DayforceSyncProcessEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "DayforceSyncProcessEndpoint"),
ActionCreditCardProcessEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "ActionCreditCardProcessEndpoint"),
ActionVehicleProcessEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "ActionVehicleProcessEndpoint"),
GapMbpProcessEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "GapMbpProcessEndpoint"),
IncentiveProcessesEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "IncentiveProcessesEndpoint"),
NightlyIncentiveProcessesEndpoint = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(configuration, "NightlyIncentiveProcessesEndpoint")
};
services.AddSingleton(receiveEndpointConfigurations);
AddMassTransitServices(ref services, connectionConfiguration, receiveEndpointConfigurations, _apiConfiguration);
AddApiServices(services);
AddDataAccess(services);
AddApiRepositories(services);
services.AddHttpContextAccessor();
services.AddLCUStatusServicesWithApiHealthCheck(configuration);
services.AddLCUHttpServices();
services.AddLCUServiceFactoryAndValidateServiceRegistration<IIncentiveProcessesService>(servicesFactoryConfiguration);
services.AddLCUServiceFactoryAndValidateServiceRegistration<INightlyIncentiveProcessesService>(servicesFactoryConfiguration);
services.Configure<ApiBehaviorOptions>(options =>
{
options.SuppressModelStateInvalidFilter = true;
});
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.Converters.Add(new StringEnumConverter());
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});
services.AddEndpointsApiExplorer();
}
void AddMassTransitServices(ref IServiceCollection services,
ConnectionConfiguration connectionConfiguration,
ReceiveEndpointConfigurations receiveEndpointConfigurations,
ApiConfiguration configuration)
{
services.AddMassTransit(x =>
{
x.AddConsumer<ImportCreditCardSalesConsumer>();
x.AddConsumer<ImportIndirectVehicleSalesConsumer>();
x.AddConsumer<ReportingConsumer>();
x.AddConsumer<GoalDispersalConsumer>();
x.AddConsumer<PayoutIncentiveConsumer>();
x.AddConsumer<DayforceSyncProcessConsumer>();
x.AddConsumer<AlliedGapMbpConsumer>();
x.AddConsumer<ActionCreditCardConsumer>();
x.AddConsumer<ActionVehicleConsumer>();
x.AddConsumer<IncentiveProcessesConsumer>();
x.AddConsumer<NightlyIncentiveProcessesConsumer>();
x.UsingRabbitMq((context, cfg) =>
{
cfg.Host(connectionConfiguration.HostUrl, "/", host =>
{
host.Username(connectionConfiguration.UserName);
host.Password(connectionConfiguration.Password);
});
if (configuration.FeatureFlags.RunImportCreditCardSalesConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.ImportCreditCardSalesEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<ImportCreditCardSalesConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.ImportCreditCardSalesEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunImportIndirectVehicleSalesConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.ImportIndirectVehicleSalesEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<ImportIndirectVehicleSalesConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.ImportIndirectVehicleSalesEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunReportingProcessConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.ReportingProcessEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<ReportingConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.ReportingProcessEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunGoalDispersalProcessConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.GoalDispersalProcessEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<GoalDispersalConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.GoalDispersalProcessEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunPayoutIncentiveProcessConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.PayoutIncentiveProcessEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<PayoutIncentiveConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.PayoutIncentiveProcessEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunDayforceSyncProcessConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.DayforceSyncProcessEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<DayforceSyncProcessConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.DayforceSyncProcessEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunGapMbpProcessConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.GapMbpProcessEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<AlliedGapMbpConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.GapMbpProcessEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunActionCreditCardProcessConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.ActionCreditCardProcessEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<ActionCreditCardConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.ActionCreditCardProcessEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunActionVehicleProcessConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.ActionVehicleProcessEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<ActionVehicleConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.ActionVehicleProcessEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunIncentiveProcessesConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.IncentiveProcessesEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<IncentiveProcessesConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.IncentiveProcessesEndpoint.PrefetchLimit;
});
}
if (configuration.FeatureFlags.RunNightlyIncentiveProcessesConsumer)
{
cfg.ReceiveEndpoint(receiveEndpointConfigurations.NightlyIncentiveProcessesEndpoint.ReceiveEndpoint, e =>
{
e.ConfigureConsumer<NightlyIncentiveProcessesConsumer>(context);
e.SetQuorumQueue();
e.PrefetchCount = receiveEndpointConfigurations.NightlyIncentiveProcessesEndpoint.PrefetchLimit;
});
}
});
});
services.AddMassTransitHostedService();
}
void AddApiServices(IServiceCollection services)
{
services.AddScoped<IActivityService, ActivityService>();
services.AddScoped<IActivityDetailService, ActivityDetailService>();
services.AddScoped<DebtProtectionAccessoryService, DebtProtectionAccessoryService>();
services.AddScoped<ISettingsService, SettingsService>();
services.AddScoped<IGoalService, GoalService>();
services.AddScoped<IDepartmentService, DepartmentService>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<IDashboardService, DashboardService>();
services.AddScoped<IDayForceClientService, DayForceClientService>();
services.AddScoped<IDayForceSyncService, DayForceSyncService>();
services.AddScoped<ICommissionService, CommissionService>();
services.AddScoped<IProcessorHistoryService, ProcessorHistoryService>();
services.AddScoped<IPayoutService, PayoutService>();
services.AddScoped<IPayoutCalculateService, PayoutCalculateService>();
services.AddScoped<IGoalDispersalService, GoalDispersalService>();
services.AddScoped<IUserAssignmentService, UserAssignmentService>();
services.AddScoped<IExternalActivityService, ExternalActivityService>();
services.AddScoped<IAlliedGapMbpTransactionImportService, AlliedGapMbpTransactionImportService>();
services.AddScoped<IActionVehicleImportService, ActionVehicleImportService>();
services.AddScoped<IActionCreditCardImportService, ActionCreditCardImportService>();
services.AddScoped<IAuthorizationService, AuthorizationService>();
services.AddScoped<IDnaService, DnaService>();
services.AddScoped<IDeadActivityService, DeadActivityService>();
services.AddScoped<IBusinessRuleService, BusinessRuleService>();
services.AddScoped<IGapInsuranceActivityService, GapInsuranceActivityService>();
services.AddScoped<IEStatementService, EStatementService>();
services.AddScoped<IReportingService, ReportingService>();
services.AddScoped<IImportCreditCardSalesService, ImportCreditCardSalesService>();
services.AddScoped<IImportIndirectVehicleSalesService, ImportIndirectVehicleSalesService>();
services.AddScoped<IDnaActivitySyncService, DnaActivitySyncService>();
services.AddScoped<INightlyActivityDecisionService, NightlyActivityDecisionService>();
services.AddScoped<IApplicationDbIntegrityService, ApplicationDbIntegrityService>();
AddQueueServices(services);
AddMicroServices(services);
AddSyncServices(services);
AddNightlyServices(services);
AddStrategyServices(services);
AddHostedServices(services);
}
void AddQueueServices(IServiceCollection services)
{
services.AddScoped<IQueueCreditCardImportService, QueueCreditCardImportService>();
services.AddScoped<IQueueIndirectVehicleImportService, QueueIndirectVehicleImportService>();
services.AddScoped<IQueueDayforceSyncService, QueueDayforceSyncService>();
services.AddScoped<IQueuePayoutIncentiveService, QueuePayoutIncentiveService>();
services.AddScoped<IQueueGoalDispersalService, QueueGoalDispersalService>();
services.AddScoped<IQueueAlliedGapMbpService, QueueAlliedGapMbpService>();
services.AddScoped<IQueueIncentiveProcessesService, QueueIncentiveProcessesService>();
services.AddScoped<IQueueNightlyIncentiveProcessesService, QueueNightlyIncentiveProcessesService>();
services.AddScoped<IQueueActionCreditCardService, QueueActionCreditCardService>();
services.AddScoped<IQueueActionVehicleService, QueueActionVehicleService>();
services.AddScoped<IQueueReportingService, QueueReportingService>();
}
void AddSyncServices(IServiceCollection services)
{
services.AddScoped<IDnaActivityProcessingService, DnaActivityProcessingService>();
services.AddScoped<IIncentiveProcessesService, AtmCheckCardActivityService>();
services.AddScoped<IIncentiveProcessesService, DpEligibleLoanSalesActivityService>();
services.AddScoped<IIncentiveProcessesService, MortgageSaleActivityService>();
services.AddScoped<IIncentiveProcessesService, NewCheckingAccountActivityService>();
services.AddScoped<IIncentiveProcessesService, NewDigitalCheckingAccountActivityService>();
services.AddScoped<IIncentiveProcessesService, ReferralActivityService>();
services.AddScoped<IIncentiveProcessesService, VehicleSalesActivityService>();
}
void AddNightlyServices(IServiceCollection services)
{
services.AddScoped<INightlyIncentiveProcessesService, DirectDepositActivityDecisionService>();
services.AddScoped<INightlyIncentiveProcessesService, ReferralActivityDecisionService>();
services.AddScoped<INightlyIncentiveProcessesService, AccountActivityDecisionService>();
services.AddScoped<INightlyIncentiveProcessesService, LICActivityDecisionService>();
services.AddScoped<INightlyIncentiveProcessesService, EStatementReferralActivityDecisionService>();
}
void AddApiRepositories(IServiceCollection services)
{
services.AddScoped<IUnitOfWork, UnitOfWork>();
services.AddScoped<IActivityRepository, ActivityRepository>();
services.AddScoped<IActivityChangeRepository, ActivityChangeRepository>();
services.AddScoped<IActivityDetailUpdateRepository, ActivityDetailUpdateRepository>();
services.AddScoped<IGoalChangeRepository, GoalChangeRepository>();
services.AddScoped<IGoalRepository, GoalRepository>();
services.AddScoped<IDepartmentRepository, DepartmentRepository>();
services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<ICommissionRepository, CommissionRepository>();
services.AddScoped<IProcessorHistoryRepository, ProcessorHistoryRepository>();
services.AddScoped<IPayoutRepository, PayoutRepository>();
services.AddScoped<IUserAssignmentRepository, UserAssignmentRepository>();
services.AddScoped<IActivityTransferActionRepository, ActivityTransferActionRepository>();
services.AddScoped<IDeadActivityRepository, DeadActivityRepository>();
services.AddScoped<IAccountingRepository, AccountingRepository>();
services.AddScoped<IUserPermissionHistoryRepository, UserPermissionHistoryRepository>();
services.AddScoped<IUserDepartmentHistoryRepository, UserDepartmentHistoryRepository>();
services.AddScoped<IRoleMappingRepository, RoleMappingRepository>();
}
void AddDataAccess(IServiceCollection services)
{
services.AddScoped<IFileOperationsApiDao, FileOperationsApiDao>();
services.AddScoped<ICoreApiWrapperDao, CoreApiWrapperDao>();
services.AddScoped<INotificationApiDao, NotificationApiDao>();
}
void AddMicroServices(IServiceCollection services)
{
services.AddScoped<IFileOperationsApiService, FileOperationsApiService>();
services.AddScoped<ICoreApiWrapperService, CoreApiWrapperService>();
services.AddScoped<INotificationApiService, NotificationApiService>();
}
void AddHostedServices(IServiceCollection services)
{
services.AddSingleton<IApplicationDbIntegrityHostedService, ApplicationDbIntegrityHostedService>();
}
void AddStrategyServices(IServiceCollection services)
{
services.AddScoped<IActivityDecisionService, ActivityDecisionService>();
services.AddScoped<IPayoutStrategy, DefaultPayoutStrategy>();
services.AddScoped<IPayoutStrategy, GapPayoutStrategy>();
services.AddScoped<IDispersalStrategyService, DispersalStrategyService>();
services.AddScoped<IDuplicateDetectionService, DuplicateDetectionService>();
services.AddScoped<IDuplicateDetectionStrategy, DefaultDuplicateDetectionStrategy>();
services.AddScoped<IDuplicateDetectionStrategy, ReferralDuplicateDetectionStrategy>();
services.AddScoped<IDuplicateDetectionStrategy, SourceIdDuplicateDetectionStrategy>();
services.AddScoped<IDecisionStrategy, CardSaleDecisionStrategy>();
services.AddScoped<IDecisionStrategy, DebtProtectionDecisionStrategy>();
services.AddScoped<IDecisionStrategy, DebtProtectionEligibleLoanDecisionStrategy>();
services.AddScoped<IDecisionStrategy, GapDecisionStrategy>();
services.AddScoped<IDecisionStrategy, ManualDecisionStrategy>();
services.AddScoped<IDecisionStrategy, MbpDecisionStrategy>();
services.AddScoped<IDecisionStrategy, MortgageSaleDecisionStrategy>();
services.AddScoped<IDecisionStrategy, NewCheckingDecisionStrategy>();
services.AddScoped<IDecisionStrategy, ReferralDecisionStrategy>();
services.AddScoped<IDecisionStrategy, VehicleDecisionStrategy>();
services.AddScoped<IExternalActivityStrategy, NewAtmCheckCardActivityStrategy>();
services.AddScoped<IExternalActivityStrategy, NewCheckingAccountActivityStrategy>();
services.AddScoped<IExternalActivityStrategy, NewDebtProtectionEligibleLoanStrategy>();
services.AddScoped<IExternalActivityStrategy, NewIncentiveManagerActivityStrategy>();
services.AddScoped<IExternalActivityStrategy, NewMortgageActivityStrategy>();
services.AddScoped<IExternalActivityStrategy, NewVehicleActivityStrategy>();
}
void BuildAppAndRun(WebApplicationBuilder builder)
{
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
if (_apiConfiguration.FeatureFlags.RunApplicationDbIntegrityHostedService)
{
var service = app.Services.GetRequiredService<IApplicationDbIntegrityHostedService>();
service.StartAsync().Wait();
}
app.UseSwagger(c =>
{
c.PreSerializeFilters.Add((swaggerDoc, request) =>
{
const string prefixHeader = "X-Forwarded-Prefix";
if (!request.Headers.ContainsKey(prefixHeader)) return;
var serverUrl = request.Headers[prefixHeader];
swaggerDoc.Servers = new List<OpenApiServer>()
{
new() { Description = serverUrl, Url = serverUrl }
};
});
});
app.UseSwaggerUI(c =>
{
c.RoutePrefix = "swagger";
c.SwaggerEndpoint("v1/swagger.json", "LCU.API.Internal.Operations.IncentiveApi v1");
});
app.UseMiddleware<RequestResponseLoggingMiddleware>();
app.UseSerilogRequestLogging(options =>
{
options.EnrichDiagnosticContext = RequestResponseLoggingMiddleware.RequestDataParser.EnrichFromRequest;
});
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseCors(MyAllowSpecificOrigins);
app.UseHttpsRedirection();
app.MapControllers();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
app.Run();
}