umbau auf enviroment appsettings
All checks were successful
Restart Docker Container on Production / build (pull_request) Successful in 3m2s

This commit is contained in:
Tobias Wohlleben 2024-09-24 23:13:52 +02:00
parent c7f81e2172
commit 18fd6d6f59
5 changed files with 48 additions and 11 deletions

View File

@ -1,7 +1,13 @@
using CommunityToolkit.Maui; using CommunityToolkit.Maui;
using CommunityToolkit.Maui.Markup; using CommunityToolkit.Maui.Markup;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using RBLNews.Maui.Services;
using RBLNews.Shared.Models;
using RBLNews.Shared.Services; using RBLNews.Shared.Services;
using RBLNews.Shared.Services.Contracts;
namespace RBLNews.Maui namespace RBLNews.Maui
{ {
@ -22,7 +28,7 @@ namespace RBLNews.Maui
builder.Services.AddMauiBlazorWebView(); builder.Services.AddMauiBlazorWebView();
builder.Services.AddBlazorBootstrap(); builder.Services.AddBlazorBootstrap();
builder.Services.AddSingleton<IConfigService, ConfigService>();
builder.Services.AddSingleton<IFeedDataService, FeedDataService>(); builder.Services.AddSingleton<IFeedDataService, FeedDataService>();
builder.Services.AddSingleton<AppLifecycleService>(); builder.Services.AddSingleton<AppLifecycleService>();
@ -33,15 +39,11 @@ namespace RBLNews.Maui
MauiApp app = builder.Build(); MauiApp app = builder.Build();
using var serviceScope = app.Services.CreateScope(); AppSettingsModel? appSettings = app.Configuration.GetSection("App").Get<AppSettingsModel>();
var services = serviceScope.ServiceProvider;
var environmentVariablesService = services.GetRequiredService<EnvironmentVariablesService>(); if (string.IsNullOrEmpty(appSettings?.BackendApiUrl))
string? backendApiUrl = environmentVariablesService.RblApiUrl;
if (string.IsNullOrEmpty(backendApiUrl))
{ {
throw new Exception($"can't instantiate services, due to paramters are null. backendApiUrl: '{backendApiUrl}'"); throw new Exception($"can't instantiate services, due to paramters are null. backendApiUrl: '{appSettings?.BackendApiUrl}'");
} }
return app; return app;

View File

@ -90,6 +90,21 @@
<Folder Include="IaC\" /> <Folder Include="IaC\" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="..\RBLNews.Shared\wwwroot\appsettings.Development.json">
<Link>wwwroot\appsettings.Development.json</Link>
</Content>
<Content Include="..\RBLNews.Shared\wwwroot\appsettings.json">
<Link>wwwroot\appsettings.json</Link>
</Content>
<Content Include="..\RBLNews.Shared\wwwroot\appsettings.Production.json">
<Link>wwwroot\appsettings.Production.json</Link>
</Content>
<Content Include="..\RBLNews.Shared\wwwroot\appsettings.Test.json">
<Link>wwwroot\appsettings.Test.json</Link>
</Content>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties XamarinHotReloadDebuggerTimeoutExceptionRBLNewsMauiHideInfoBar="True" /></VisualStudio></ProjectExtensions> <ProjectExtensions><VisualStudio><UserProperties XamarinHotReloadDebuggerTimeoutExceptionRBLNewsMauiHideInfoBar="True" /></VisualStudio></ProjectExtensions>
</Project> </Project>

View File

@ -0,0 +1,20 @@
using Microsoft.Extensions.Configuration;
using RBLNews.Shared.Models;
using RBLNews.Shared.Services.Contracts;
namespace RBLNews.Maui.Services;
public class ConfigService : IConfigService
{
public AppSettingsModel? AppSettings { get; }
public ConfigService(IConfiguration configuration)
{
this.AppSettings = configuration.GetSection("App").Get<AppSettingsModel>();
if(this.AppSettings == null)
{
throw new NullReferenceException("App settings not found");
}
}
}

View File

@ -4,5 +4,5 @@ namespace RBLNews.Shared.Services.Contracts;
public interface IConfigService public interface IConfigService
{ {
AppSettingsModel AppSettings { get; } AppSettingsModel? AppSettings { get; }
} }

View File

@ -5,7 +5,7 @@ namespace RBLNews.Web.Services;
public class ConfigService : IConfigService public class ConfigService : IConfigService
{ {
public AppSettingsModel AppSettings { get; } public AppSettingsModel? AppSettings { get; }
public ConfigService(IConfiguration configuration) public ConfigService(IConfiguration configuration)
{ {