127 lines
5.8 KiB
C#
127 lines
5.8 KiB
C#
using System.Collections.Concurrent;
|
|
using DelforSenders.Clients;
|
|
using DelforSenders.Clients.Brose;
|
|
using DelforSenders.Clients.Edscha;
|
|
using DelforSenders.Clients.Iac;
|
|
using DelforSenders.Clients.Scania;
|
|
using DelforSenders.Clients.Stellantis;
|
|
using DelforSenders.Clients.StellantisArgentina;
|
|
using DelforSenders.Clients.Strattec;
|
|
using DelforSenders.Clients.Tofas;
|
|
using DelforSenders.Core;
|
|
using DelforSenders.Enrichers;
|
|
using DelforSenders.Logger;
|
|
using DelforSenders.Models;
|
|
using DelforSenders.Services;
|
|
using DelforSenders.Translators;
|
|
using FaKrosnoEfDataModel;
|
|
using FaKrosnoEfDataModel.Dtos;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using PublicHoliday;
|
|
using RestSharp;
|
|
using SytelineSaAppEfDataModel;
|
|
using SytelineSaAppEfDataModel.Dtos;
|
|
using FaKrosnoMappingProfile = FaKrosnoEfDataModel.MappingProfile;
|
|
using SytelineSaAppMappingProfile = SytelineSaAppEfDataModel.MappingProfile;
|
|
|
|
namespace DelforSenders;
|
|
|
|
public class Builder
|
|
{
|
|
public IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureAppConfiguration((_, config) =>
|
|
{
|
|
config.AddJsonFile("appSettings.json", optional: false, reloadOnChange: true);
|
|
})
|
|
.ConfigureServices((hostContext, services) =>
|
|
{
|
|
var configuration = hostContext.Configuration;
|
|
var sytelineConnection = configuration.GetConnectionString("SytelineSaAppConnection");
|
|
var faKrosnoConnection = configuration.GetConnectionString("FaKrosnoConnection");
|
|
var logMessages = new ConcurrentBag<string>();
|
|
|
|
string faKrosnoApiUrl = "http://localhost:5001";
|
|
|
|
services.AddHttpClient("FaKrosnoApi", client =>
|
|
{
|
|
client.BaseAddress = new Uri(faKrosnoApiUrl);
|
|
});
|
|
|
|
services.AddSingleton<ConcurrentQueue<string>>();
|
|
|
|
services.AddSingleton<AppLogger>(provider =>
|
|
{
|
|
var messages = provider.GetRequiredService<ConcurrentQueue<string>>();
|
|
return new AppLogger("AppLogger", messages);
|
|
});
|
|
|
|
services.AddSingleton<AppLoggerProvider>(provider =>
|
|
{
|
|
var messages = provider.GetRequiredService<ConcurrentQueue<string>>();
|
|
return new AppLoggerProvider(messages);
|
|
});
|
|
|
|
services.AddLogging(builder =>
|
|
{
|
|
builder.ClearProviders();
|
|
builder.AddProvider(services.BuildServiceProvider().GetRequiredService<AppLoggerProvider>());
|
|
});
|
|
|
|
services.AddSingleton<IRestClient>(provider =>
|
|
{
|
|
var httpClient = provider.GetRequiredService<IHttpClientFactory>().CreateClient("FaKrosnoApi");
|
|
return new RestClient(httpClient);
|
|
});
|
|
|
|
services.AddDbContext<SytelineSaAppDbContext>(options => options.UseSqlServer(sytelineConnection));
|
|
services.AddDbContext<FaKrosnoDbContext>(options => options.UseSqlServer(faKrosnoConnection));
|
|
|
|
services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile));
|
|
services.AddScoped<IPublicHolidays, PolandPublicHoliday>();
|
|
|
|
services.AddScoped<IEmailGeneratorService, EmailGeneratorService>();
|
|
|
|
services.AddScoped<IValidator, Validator>();
|
|
services.AddScoped<IValidatorService, ValidatorService>();
|
|
services.AddScoped<IAppService, AppService>();
|
|
services.AddScoped<IClientService, ClientService>();
|
|
services.AddScoped<IApp, App>();
|
|
|
|
services
|
|
.AddScoped<ITranslator<EdiCustomerOrderDto, ScheduleOrderDto>, ScheduleOrderToEdiCoTranslator>();
|
|
services
|
|
.AddScoped<ITranslator<EdiCustomerOrderLineDto, ScheduleOrderDetailDto>,
|
|
ScheduleOrderDetailToEdiCoBlnTranslator>();
|
|
services
|
|
.AddScoped<ITranslator<EdiCustomerOrderLineItemDto, ScheduleOrderDetailDetailDto>,
|
|
ScheduleOrderDetailDetailToEdiCoItemTranslator>();
|
|
|
|
services.AddScoped<IClient, ClientBrose>();
|
|
services.AddScoped<IClient, ClientScania>();
|
|
services.AddScoped<IClient, ClientStellantis>();
|
|
services.AddScoped<IClient, ClientIac>();
|
|
services.AddScoped<IClient, ClientStrattec>();
|
|
services.AddScoped<IClient, ClientEdscha>();
|
|
services.AddScoped<IClient, ClientTofas>();
|
|
services.AddScoped<IClient, ClientStellantisArgentina>();
|
|
|
|
services.AddScoped<IClientFactory, ClientFactory>();
|
|
|
|
services.AddScoped<IEnricher<EdiCustomerOrderDto, CustomerDto>, CustomerEnricher>();
|
|
services
|
|
.AddScoped<IEnricher<EdiCustomerOrderLineDto, CustomerOrderLineDto>, CustomerOrderLineEnricher>();
|
|
services
|
|
.AddScoped<IEnricher<EdiCustomerOrderLineDto, ItemDto>, ItemEnricher>();
|
|
services
|
|
.AddScoped<IEnricher<EdiCustomerOrderLineDto, ItemCustPriceAllDto>, ItemPriceEnricher>();
|
|
services
|
|
.AddScoped<IEnricher<EdiCustomerOrderLineItemDto, EdiCustomerOrderLineDto>,
|
|
EdiCustomerOrderLineEnricher>();
|
|
services.AddScoped<IEnricher<EdiCustomerOrderDto, CustomerOrderDto>, CustomerOrderEnricher>();
|
|
});
|
|
} |