build script for maui apk adjusted 2 #2
@ -1,7 +1,13 @@
|
||||
using CommunityToolkit.Maui;
|
||||
using CommunityToolkit.Maui.Markup;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using RBLNews.Maui.Services;
|
||||
using RBLNews.Shared.Models;
|
||||
using RBLNews.Shared.Services;
|
||||
using RBLNews.Shared.Services.Contracts;
|
||||
|
||||
namespace RBLNews.Maui
|
||||
{
|
||||
@ -22,7 +28,7 @@ namespace RBLNews.Maui
|
||||
|
||||
builder.Services.AddMauiBlazorWebView();
|
||||
builder.Services.AddBlazorBootstrap();
|
||||
|
||||
builder.Services.AddSingleton<IConfigService, ConfigService>();
|
||||
builder.Services.AddSingleton<IFeedDataService, FeedDataService>();
|
||||
builder.Services.AddSingleton<AppLifecycleService>();
|
||||
|
||||
@ -33,15 +39,11 @@ namespace RBLNews.Maui
|
||||
|
||||
MauiApp app = builder.Build();
|
||||
|
||||
using var serviceScope = app.Services.CreateScope();
|
||||
var services = serviceScope.ServiceProvider;
|
||||
AppSettingsModel? appSettings = app.Configuration.GetSection("App").Get<AppSettingsModel>();
|
||||
|
||||
var environmentVariablesService = services.GetRequiredService<EnvironmentVariablesService>();
|
||||
string? backendApiUrl = environmentVariablesService.RblApiUrl;
|
||||
|
||||
if (string.IsNullOrEmpty(backendApiUrl))
|
||||
if (string.IsNullOrEmpty(appSettings?.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;
|
||||
|
||||
@ -90,6 +90,21 @@
|
||||
<Folder Include="IaC\" />
|
||||
</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>
|
||||
|
||||
</Project>
|
||||
|
||||
20
RBLNews.Maui/Services/ConfigService.cs
Normal file
20
RBLNews.Maui/Services/ConfigService.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,5 +4,5 @@ namespace RBLNews.Shared.Services.Contracts;
|
||||
|
||||
public interface IConfigService
|
||||
{
|
||||
AppSettingsModel AppSettings { get; }
|
||||
AppSettingsModel? AppSettings { get; }
|
||||
}
|
||||
@ -5,7 +5,7 @@ namespace RBLNews.Web.Services;
|
||||
|
||||
public class ConfigService : IConfigService
|
||||
{
|
||||
public AppSettingsModel AppSettings { get; }
|
||||
public AppSettingsModel? AppSettings { get; }
|
||||
|
||||
public ConfigService(IConfiguration configuration)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user