adding
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
using LCU.API.Internal.DocumentLib.Configurations;
|
||||
using LCU.API.Internal.DocumentLib.Utilities;
|
||||
using LCU.Library.Internal.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using OwnerNumberMigration;
|
||||
using OwnerNumberMigration.Logging;
|
||||
using OwnerNumberMigration.Migrations;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
using Azure.Identity;
|
||||
using LCU.API.Internal.DocumentLib.Containers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OwnerNumberMigration.ValueParsing;
|
||||
using Serilog;
|
||||
using LCU.Library.Internal.Logging.Models;
|
||||
using LCU.Library.Internal.Logging;
|
||||
|
||||
await Host.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration((host, configuration) =>
|
||||
{
|
||||
var vaultConfiguration = configuration.Build();
|
||||
var clientSecretCredentials = new ClientSecretCredential
|
||||
(
|
||||
vaultConfiguration["TenantId"],
|
||||
vaultConfiguration["ClientId"],
|
||||
vaultConfiguration["ClientSecret"]
|
||||
);
|
||||
var vaultLocation = new Uri($"https://{vaultConfiguration["AzureKeyVaultUrl"]}.vault.azure.net/");
|
||||
|
||||
configuration.AddAzureKeyVault(vaultLocation, clientSecretCredentials);
|
||||
})
|
||||
/* remove for local */
|
||||
.UseSerilog()
|
||||
/* to here */
|
||||
/* local:
|
||||
.ConfigureLogging(logging =>
|
||||
{
|
||||
logging
|
||||
.AddConsole()
|
||||
.AddFile("Logs/OwnerMigration-{Date}.log", isJson: true)
|
||||
.SetMinimumLevel(LogLevel.Information);
|
||||
})
|
||||
*/
|
||||
.ConfigureServices((host, services) =>
|
||||
{
|
||||
services.RegisterOwnerMigrationServices();
|
||||
|
||||
host.Configuration.Bind<DatabaseConfiguration>(services, "MongoDatabase");
|
||||
host.Configuration.Bind<NotificationApiConfiguration>(services, "NotificationApiConfiguration");
|
||||
|
||||
/* remove for local */
|
||||
var loggingConfiguration = host.Configuration.GetSection("Primary");
|
||||
var loggerConfiguration = new LoggingConfiguration
|
||||
(
|
||||
loggingConfiguration["AppName"],
|
||||
loggingConfiguration["SeqUrl"],
|
||||
loggingConfiguration["SeqApiKey"]
|
||||
);
|
||||
var lcuLogging = new LcuLogging(loggerConfiguration);
|
||||
lcuLogging.UseLcuLogging();
|
||||
/* to here */
|
||||
})
|
||||
.RunConsoleAsync();
|
||||
|
||||
public static class ServiceRegistrationExtension
|
||||
{
|
||||
public static IServiceCollection RegisterOwnerMigrationServices(this IServiceCollection services)
|
||||
{
|
||||
ServiceRegistrations.AddDocumentRepositories(services);
|
||||
services.AddTransient<ILogger>(p => p.GetRequiredService<ILogger<DocumentInformation>>());
|
||||
services.AddTransient<SingleValueStrategy>();
|
||||
services.AddTransient<SingleValueArrayStrategy>();
|
||||
services.AddTransient<CommaStringArrayStrategy>();
|
||||
services.AddTransient<IParsingStrategyFactory, ParsingStrategyFactory>();
|
||||
services.AddTransient<IDocumentFilterFactory, DocumentFilterFactory>();
|
||||
services.AddTransient<AttributeMigrationLoggingDecoratorFactory>(p => (migration, name, destination) =>
|
||||
new AttributeMigrationLoggingDecorator
|
||||
(
|
||||
migration,
|
||||
p.GetRequiredService<ILogger>(),
|
||||
p.GetRequiredService<IMongoCollectionFactory>(),
|
||||
name,
|
||||
destination,
|
||||
p.GetRequiredService<IDocumentFilterFactory>()
|
||||
)
|
||||
);
|
||||
services.AddTransient<AttributeMigrationLoggingObserverFactory>(p => name =>
|
||||
new AttributeMigrationLoggingObserver
|
||||
(
|
||||
p.GetRequiredService<ILogger>(),
|
||||
name
|
||||
)
|
||||
);
|
||||
services.AddTransient<AttributeMigrationFactory<string>>(p => (name, strategy, property) =>
|
||||
p.GetRequiredService<AttributeMigrationLoggingDecoratorFactory>()
|
||||
(
|
||||
new AttributeMigration<string>
|
||||
(
|
||||
p.GetRequiredService<IMongoCollectionFactory>(),
|
||||
name,
|
||||
strategy,
|
||||
property,
|
||||
p.GetRequiredService<AttributeMigrationLoggingObserverFactory>()(name),
|
||||
p.GetRequiredService<IDocumentFilterFactory>()
|
||||
),
|
||||
name,
|
||||
property
|
||||
)
|
||||
);
|
||||
services.AddTransient<AttributeMigrationFactory<string[]>>(p => (name, strategy, property) =>
|
||||
p.GetRequiredService<AttributeMigrationLoggingDecoratorFactory>()
|
||||
(
|
||||
new AttributeMigration<string[]>
|
||||
(
|
||||
p.GetRequiredService<IMongoCollectionFactory>(),
|
||||
name,
|
||||
strategy,
|
||||
property,
|
||||
p.GetRequiredService<AttributeMigrationLoggingObserverFactory>()(name),
|
||||
p.GetRequiredService<IDocumentFilterFactory>()
|
||||
),
|
||||
name,
|
||||
property
|
||||
)
|
||||
);
|
||||
|
||||
services.AddSingleton<IMigrationManager, MigrationManager>();
|
||||
services.AddHostedService<PersonNumberMigration>();
|
||||
services.AddHostedService<PersonNumbersMigration>();
|
||||
services.AddHostedService<OrganizationNumberMigration>();
|
||||
services.AddHostedService<OrganizationNumbersMigration>();
|
||||
services.AddHostedService<AccountNumberMigration>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user