umbau auf enviroment appsettings
All checks were successful
Restart Docker Container on Production / build (pull_request) Successful in 4m31s
All checks were successful
Restart Docker Container on Production / build (pull_request) Successful in 4m31s
This commit is contained in:
parent
aa03b6ae83
commit
20f9454f80
@ -1,4 +1,4 @@
|
|||||||
namespace RBLNews.Web.Models;
|
namespace RBLNews.Shared.Models;
|
||||||
|
|
||||||
public class AppSettingsModel
|
public class AppSettingsModel
|
||||||
{
|
{
|
||||||
8
RBLNews.Shared/Services/Contracts/IConfigService.cs
Normal file
8
RBLNews.Shared/Services/Contracts/IConfigService.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using RBLNews.Shared.Models;
|
||||||
|
|
||||||
|
namespace RBLNews.Shared.Services.Contracts;
|
||||||
|
|
||||||
|
public interface IConfigService
|
||||||
|
{
|
||||||
|
AppSettingsModel AppSettings { get; }
|
||||||
|
}
|
||||||
@ -2,6 +2,8 @@
|
|||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using RBLFeederCommon.Models.RssFeed;
|
using RBLFeederCommon.Models.RssFeed;
|
||||||
|
|
||||||
|
using RBLNews.Shared.Services.Contracts;
|
||||||
|
|
||||||
namespace RBLNews.Shared.Services
|
namespace RBLNews.Shared.Services
|
||||||
{
|
{
|
||||||
public interface IFeedDataService
|
public interface IFeedDataService
|
||||||
@ -15,7 +17,7 @@ namespace RBLNews.Shared.Services
|
|||||||
|
|
||||||
public class FeedDataService : IFeedDataService
|
public class FeedDataService : IFeedDataService
|
||||||
{
|
{
|
||||||
private readonly EnvironmentVariablesService _environmentVariablesService;
|
private readonly IConfigService _configService;
|
||||||
|
|
||||||
private static readonly HttpClient httpClient = new();
|
private static readonly HttpClient httpClient = new();
|
||||||
|
|
||||||
@ -23,15 +25,14 @@ namespace RBLNews.Shared.Services
|
|||||||
|
|
||||||
public Action DataChanged { get; set; }
|
public Action DataChanged { get; set; }
|
||||||
|
|
||||||
|
public FeedDataService(IConfigService configService)
|
||||||
public FeedDataService(EnvironmentVariablesService environmentVariablesService)
|
|
||||||
{
|
{
|
||||||
this._environmentVariablesService = environmentVariablesService;
|
this._configService = configService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task LoadFeeds()
|
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();
|
DataChanged.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
|
using RBLNews.Shared.Models;
|
||||||
using RBLNews.Shared.Services;
|
using RBLNews.Shared.Services;
|
||||||
|
using RBLNews.Shared.Services.Contracts;
|
||||||
using RBLNews.Web.Components;
|
using RBLNews.Web.Components;
|
||||||
using RBLNews.Web.Services;
|
using RBLNews.Web.Services;
|
||||||
|
|
||||||
@ -9,10 +11,9 @@ builder.Services.AddRazorComponents()
|
|||||||
.AddInteractiveServerComponents();
|
.AddInteractiveServerComponents();
|
||||||
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>();
|
||||||
builder.Services.AddSingleton<EnvironmentVariablesService>();
|
|
||||||
builder.Services.AddSingleton<ConfigService>();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
@ -25,24 +26,11 @@ if (!app.Environment.IsDevelopment())
|
|||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
using var serviceScope = app.Services.CreateScope();
|
AppSettingsModel? appSettings = app.Configuration.GetSection("App").Get<AppSettingsModel>();
|
||||||
IServiceProvider services = serviceScope.ServiceProvider;
|
|
||||||
|
|
||||||
var logger = LoggerFactory.Create(config =>
|
if (string.IsNullOrEmpty(appSettings?.BackendApiUrl))
|
||||||
{
|
{
|
||||||
config.AddConsole();
|
throw new Exception($"can't instantiate services, due to paramters are null. backendApiUrl: '{appSettings?.BackendApiUrl}'");
|
||||||
}).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}'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|||||||
@ -1,18 +1,16 @@
|
|||||||
using RBLNews.Web.Models;
|
using RBLNews.Shared.Models;
|
||||||
|
using RBLNews.Shared.Services.Contracts;
|
||||||
|
|
||||||
namespace RBLNews.Web.Services;
|
namespace RBLNews.Web.Services;
|
||||||
|
|
||||||
public class ConfigService
|
public class ConfigService : IConfigService
|
||||||
{
|
{
|
||||||
private readonly IConfiguration _configuration;
|
public AppSettingsModel AppSettings { get; }
|
||||||
|
|
||||||
public AppSettingsModel AppSettings { get; private set; }
|
|
||||||
|
|
||||||
public ConfigService(IConfiguration configuration)
|
public ConfigService(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
this._configuration = configuration;
|
|
||||||
configuration.GetSection("App").Bind(this.AppSettings);
|
|
||||||
|
|
||||||
AppSettings = configuration.GetSection("App").Get<AppSettingsModel>();
|
AppSettings = configuration.GetSection("App").Get<AppSettingsModel>();
|
||||||
|
if(this.AppSettings == null)
|
||||||
|
throw new NullReferenceException("App settings not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,6 +6,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"App": {
|
"App": {
|
||||||
"BackendApiUrl": "https://rbl.wohlleben.dev"
|
"BackendApiUrl": "https://localhost:5147"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
RBLNews.Web/appsettings.Test.json
Normal file
12
RBLNews.Web/appsettings.Test.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"App": {
|
||||||
|
"BackendApiUrl": "https://rbl.wohlleben.dev"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,8 +5,5 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*"
|
||||||
"App": {
|
|
||||||
"BackendApiUrl": "https://rblnews.de"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user