41 lines
1.9 KiB
C#
41 lines
1.9 KiB
C#
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<IMainWindowNavigator, MainWindowNavigator>();
|
|
services.AddSingleton<ViewModelDelegateRenavigator<ProjektEditViewModel>>();
|
|
|
|
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<IProjektDataService>(_=> new SewerStammGen.DAL.Services.PostgresqlData.ProjektDataService(connectionstring));
|
|
services.AddSingleton<IAuftraggeberDataService>(_ => new SewerStammGen.DAL.Services.PostgresqlData.AuftraggeberDataService(connectionstring));
|
|
services.AddSingleton<ISchachtDataService>(_ => new SewerStammGen.DAL.Services.PostgresqlData.SchachtDataService(connectionstring));
|
|
services.AddSingleton<IHaltungDataService>(_ => new SewerStammGen.DAL.Services.PostgresqlData.HaltungDataService(connectionstring));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
});
|
|
return host;
|
|
}
|
|
}
|
|
}
|