using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using SewerStammGen.Shared.Contracts; using StammGenerator.Interface; using StammGenerator.ViewModel; using System; namespace StammGenerator.HostBuilders { internal static class AddServicesHostBuilderExtensions { public static IHostBuilder AddServices(this IHostBuilder host) { host.ConfigureServices((context,services) => { services.AddSingleton(); services.AddSingleton>(); string? databaseToUse = context.Configuration.GetConnectionString("databaseToUse"); if(databaseToUse != null) { if(databaseToUse.Equals("postgresql")) { string? connectionstring = context.Configuration.GetConnectionString("postgresql"); if(connectionstring == null) throw new ArgumentNullException(nameof(connectionstring)); services.AddSingleton(_=> new SewerStammGen.DAL.Services.PostgresqlData.ProjektDataService(connectionstring)); services.AddSingleton(_ => new SewerStammGen.DAL.Services.PostgresqlData.AuftraggeberDataService(connectionstring)); services.AddSingleton(_ => new SewerStammGen.DAL.Services.PostgresqlData.SchachtDataService(connectionstring)); services.AddSingleton(_ => new SewerStammGen.DAL.Services.PostgresqlData.HaltungDataService(connectionstring)); } } }); return host; } } }