185 lines
8.9 KiB
C#
185 lines
8.9 KiB
C#
using System.Text.Json.Serialization;
|
|
using Newtonsoft.Json;
|
|
using Microsoft.OpenApi.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Serilog;
|
|
using MassTransit;
|
|
using LCU.Library.Internal.Logging.Models;
|
|
using LCU.Library.Internal.Logging;
|
|
using LCU.Library.Internal.Logging.Middleware;
|
|
using LCU.Api.Internal.DataCleanUp.Services;
|
|
using LCU.Api.Internal.DataCleanUp.DataAccess;
|
|
using LCU.Library.Internal.LcuMassTransit;
|
|
using LCU.Library.Internal.LcuMassTransitModels;
|
|
using LCU.Api.Internal.DataCleanUp.Consumers;
|
|
using LCU.Api.Internal.DataCleanUpLib.Repositories;
|
|
using LCU.Library.Internal.ApiSecurity;
|
|
using LCU.Library.Internal.Configuration;
|
|
using LCU.Api.Internal.DataCleanUp.Services.Validation;
|
|
using LCU.Api.Internal.DataCleanUp.Configuration;
|
|
using LCU.Api.Internal.DataCleanUp.Services.Emailers;
|
|
using LCU.Api.Internal.DataCleanUpLib.Persistence;
|
|
using LCU.Library.Internal.LcuHttpClient;
|
|
|
|
namespace LCU.Api.Internal.DataCleanUp;
|
|
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
public IConfiguration Configuration { get; }
|
|
readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddControllers();
|
|
services.AddHttpClient();
|
|
services.AddLCUHttpServices();
|
|
|
|
services.AddDbContext<AppDbContext>(options =>
|
|
{
|
|
options.UseSqlServer(Configuration.GetSection("Primary").GetSection("Connections").GetSection("SQL").GetSection("LtvDb").Value);
|
|
}, ServiceLifetime.Transient);
|
|
|
|
var dataCleanUpConfiguration = Configuration.Bind<DataCleanUpConfiguration>(services, "Primary");
|
|
Configuration.Bind<CoreApiWrapperConfiguration>(services);
|
|
Configuration.Bind<FileOperationsConfiguration>(services);
|
|
Configuration.Bind<SavingsMissingRequirementsDefaults>(services);
|
|
Configuration.Bind<DataCleanupDefaults>(services);
|
|
Configuration.Bind<NcoaConfiguration>(services);
|
|
Configuration.Bind<NotificationsApiConfiguration>(services);
|
|
Configuration.Bind<FannieMaeConfiguration>(services);
|
|
Configuration.Bind<IndirectSavingsRequirementsDefaults>(services);
|
|
|
|
services.AddApiKeySecurity(Configuration);
|
|
|
|
var loggerConfiguration = new LoggingConfiguration(dataCleanUpConfiguration.AppName, dataCleanUpConfiguration.SeqApiKey, dataCleanUpConfiguration.SeqUrl);
|
|
var lcuLogging = new LcuLogging(loggerConfiguration);
|
|
lcuLogging.UseLcuLogging();
|
|
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddPolicy(MyAllowSpecificOrigins,
|
|
builder =>
|
|
{
|
|
builder.WithOrigins(
|
|
dataCleanUpConfiguration.CorsAllowedOrigins
|
|
).AllowAnyHeader().AllowAnyMethod();
|
|
});
|
|
});
|
|
|
|
var connectionConfiguration = MassTransitConfigurationSetUp.AddConnectionConfiguration(ref services, Configuration);
|
|
//debugging
|
|
Console.WriteLine(JsonConvert.SerializeObject(connectionConfiguration));
|
|
var receiveEndpointConfiguration = MassTransitConfigurationSetUp.GetReceiveEndpointConfiguration(Configuration,
|
|
"DataCleanUpReceiveEndpoint");
|
|
services.AddSingleton(receiveEndpointConfiguration);
|
|
//debugging
|
|
Console.WriteLine(JsonConvert.SerializeObject(receiveEndpointConfiguration));
|
|
AddMassTransitServices(ref services, connectionConfiguration, receiveEndpointConfiguration,dataCleanUpConfiguration);
|
|
|
|
services.AddScoped<IEnvironmentView, EnvironmentView>();
|
|
AddDataCleanUpServices(ref services);
|
|
AddDataCleanUpDataAccess(ref services);
|
|
|
|
services.AddControllers().AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
|
|
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = $"{dataCleanUpConfiguration.AppName}", Version = "v1" }); });
|
|
}
|
|
|
|
public void AddDataCleanUpServices(ref IServiceCollection services)
|
|
{
|
|
services.AddScoped<IQueueDataCleanUpService, QueueDataCleanUpService>();
|
|
services.AddScoped<IDataCleanUpService, DataCleanUpService>();
|
|
services.AddScoped<IHyphenatedUserIdCleanUpService, HyphenatedUserIdCleanUpService>();
|
|
services.AddScoped<IDeactivateCustodialEAgreementsService, DeactivateCustodialEAgreementsService>();
|
|
services.AddScoped<ICloseCustodialVruAgreementsService, CloseCustodialVruAgreementsService>();
|
|
services.AddScoped<IMaskTransactionExternalDescriptionWithSsnService, MaskTransactionExternalDescriptionWithSsnService>();
|
|
services.AddScoped<IAddFundsToVipSavingsAccountsService, AddFundsToVipSavingsAccountsService>();
|
|
services.AddScoped<IBatchAddFundsToVipSavingsAccountsService, BatchAddFundsToVipSavingsAccountsService>();
|
|
services.AddScoped<ICoreApiWrapperService, CoreApiWrapperService>();
|
|
services.AddScoped<IUpdateAccountPmiCancelService, UpdateAccountPmiCancelService>();
|
|
services.AddScoped<IUpdateAccountNicknameService, UpdateAccountNicknameService>();
|
|
services.AddScoped<IUpdateAdminBranchCodesByAccountNumberService, UpdateAdminBranchCodesByAccountNumberService>();
|
|
services.AddScoped<IUpdateAccountLoanToValueService, UpdateAccountLoanToValueService>();
|
|
services.AddScoped<IUpdateAccountGroupForAnalysisService, UpdateAccountGroupForAnalysisService>();
|
|
services.AddScoped<IUpdatePersonForAtmHoldsService, UpdatePersonForAtmHoldsService>();
|
|
services.AddScoped<IUpdateMissingBatchSavingsService, UpdateMissingBatchSavingsService>();
|
|
services.AddScoped<IUpdateNcoaProcessService, UpdateNcoaProcessService>();
|
|
services.AddScoped<IUpdateAccountCreditReportTypeService, UpdateAccountCreditReportTypeService>();
|
|
services.AddScoped<IFileOperationsService, FileOperationsService>();
|
|
services.AddScoped<IUpdateFannieMaeMortgageService, UpdateFannieMaeMortgageService>();
|
|
services.AddScoped<IAddFundsToIndirectSavingsAccountsService, AddFundsToIndirectSavingsAccountsService>();
|
|
|
|
//Emailers
|
|
services.AddScoped<INotificationsApiService, NotificationsApiService>();
|
|
|
|
//Validation
|
|
services.AddScoped<INcoaValidationService, NcoaValidationService>();
|
|
|
|
//Repository
|
|
services.AddScoped<ILtvDataCleanUpRepository, LtvDataCleanUpRepository>();
|
|
}
|
|
|
|
public void AddDataCleanUpDataAccess(ref IServiceCollection services)
|
|
{
|
|
services.AddScoped<ICoreApiWrapperDao, CoreApiWrapperDao>();
|
|
services.AddScoped<IFileOperationsDao, FileOperationsDao>();
|
|
services.AddScoped<INotificationsDao, NotificationsDao>();
|
|
}
|
|
|
|
public void AddMassTransitServices(ref IServiceCollection services,
|
|
ConnectionConfiguration connectionConfiguration,
|
|
ReceiveEndpointConfiguration receiveEndpointConfiguration,
|
|
DataCleanUpConfiguration dataCleanUpConfig)
|
|
{
|
|
services.AddMassTransit(x =>
|
|
{
|
|
x.AddConsumer<DataCleanUpConsumer>();
|
|
|
|
x.UsingRabbitMq((context, cfg) =>
|
|
{
|
|
cfg.Host(connectionConfiguration.HostUrl, "/", host =>
|
|
{
|
|
host.Username(connectionConfiguration.UserName);
|
|
host.Password(connectionConfiguration.Password);
|
|
});
|
|
|
|
if (dataCleanUpConfig.FeatureFlags.RunDataCleanUpConsumer)
|
|
{
|
|
cfg.ReceiveEndpoint(receiveEndpointConfiguration.ReceiveEndpoint, e =>
|
|
{
|
|
e.ConfigureConsumer<DataCleanUpConsumer>(context);
|
|
e.PrefetchCount = receiveEndpointConfiguration.PrefetchLimit;
|
|
e.SetQuorumQueue();
|
|
});
|
|
}
|
|
});
|
|
});
|
|
services.AddMassTransitHostedService();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "LCU.Api.Internal.DataCleanUp v1"));
|
|
app.UseMiddleware<RequestResponseLoggingMiddleware>();
|
|
app.UseSerilogRequestLogging(options =>
|
|
{
|
|
options.EnrichDiagnosticContext = RequestResponseLoggingMiddleware.RequestDataParser.EnrichFromRequest;
|
|
});
|
|
|
|
app.UseRouting();
|
|
app.UseCors(MyAllowSpecificOrigins);
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
|
}
|
|
} |