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

This commit is contained in:
Tobias Wohlleben 2024-09-24 22:31:15 +02:00
parent aa03b6ae83
commit 20f9454f80
8 changed files with 41 additions and 37 deletions

View File

@ -1,4 +1,4 @@
namespace RBLNews.Web.Models;
namespace RBLNews.Shared.Models;
public class AppSettingsModel
{

View File

@ -0,0 +1,8 @@
using RBLNews.Shared.Models;
namespace RBLNews.Shared.Services.Contracts;
public interface IConfigService
{
AppSettingsModel AppSettings { get; }
}

View File

@ -2,6 +2,8 @@
using System.Net.Http.Json;
using RBLFeederCommon.Models.RssFeed;
using RBLNews.Shared.Services.Contracts;
namespace RBLNews.Shared.Services
{
public interface IFeedDataService
@ -15,7 +17,7 @@ namespace RBLNews.Shared.Services
public class FeedDataService : IFeedDataService
{
private readonly EnvironmentVariablesService _environmentVariablesService;
private readonly IConfigService _configService;
private static readonly HttpClient httpClient = new();
@ -23,15 +25,14 @@ namespace RBLNews.Shared.Services
public Action DataChanged { get; set; }
public FeedDataService(EnvironmentVariablesService environmentVariablesService)
public FeedDataService(IConfigService configService)
{
this._environmentVariablesService = environmentVariablesService;
this._configService = configService;
}
public async Task LoadFeeds()
{
Feeds = await httpClient.GetFromJsonAsync<RssVM>($"{this._environmentVariablesService.RblApiUrl}/api/feeds") ?? new RssVM();
Feeds = await httpClient.GetFromJsonAsync<RssVM>($"{this._configService.AppSettings.BackendApiUrl}/api/feeds") ?? new RssVM();
DataChanged.Invoke();
}
}

View File

@ -1,4 +1,6 @@
using RBLNews.Shared.Models;
using RBLNews.Shared.Services;
using RBLNews.Shared.Services.Contracts;
using RBLNews.Web.Components;
using RBLNews.Web.Services;
@ -9,10 +11,9 @@ builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddBlazorBootstrap();
builder.Services.AddSingleton<IConfigService, ConfigService>();
builder.Services.AddSingleton<IFeedDataService, FeedDataService>();
builder.Services.AddSingleton<AppLifecycleService>();
builder.Services.AddSingleton<EnvironmentVariablesService>();
builder.Services.AddSingleton<ConfigService>();
var app = builder.Build();
@ -25,24 +26,11 @@ if (!app.Environment.IsDevelopment())
app.UseHsts();
}
using var serviceScope = app.Services.CreateScope();
IServiceProvider services = serviceScope.ServiceProvider;
AppSettingsModel? appSettings = app.Configuration.GetSection("App").Get<AppSettingsModel>();
var logger = LoggerFactory.Create(config =>
if (string.IsNullOrEmpty(appSettings?.BackendApiUrl))
{
config.AddConsole();
}).CreateLogger("Program");
ConfigService configService = services.GetRequiredService<ConfigService>();
var a = configService.AppSettings;
EnvironmentVariablesService environmentVariablesService = services.GetRequiredService<EnvironmentVariablesService>();
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}'");
}
app.UseHttpsRedirection();

View File

@ -1,18 +1,16 @@
using RBLNews.Web.Models;
using RBLNews.Shared.Models;
using RBLNews.Shared.Services.Contracts;
namespace RBLNews.Web.Services;
public class ConfigService
public class ConfigService : IConfigService
{
private readonly IConfiguration _configuration;
public AppSettingsModel AppSettings { get; private set; }
public AppSettingsModel AppSettings { get; }
public ConfigService(IConfiguration configuration)
{
this._configuration = configuration;
configuration.GetSection("App").Bind(this.AppSettings);
AppSettings = configuration.GetSection("App").Get<AppSettingsModel>();
if(this.AppSettings == null)
throw new NullReferenceException("App settings not found");
}
}

View File

@ -6,6 +6,6 @@
}
},
"App": {
"BackendApiUrl": "https://rbl.wohlleben.dev"
"BackendApiUrl": "https://localhost:5147"
}
}

View File

@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"App": {
"BackendApiUrl": "https://rbl.wohlleben.dev"
}
}

View File

@ -5,8 +5,5 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"App": {
"BackendApiUrl": "https://rblnews.de"
}
"AllowedHosts": "*"
}