Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Jul 21, 2024
1 parent d91e77f commit 8e76ece
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit&hl=@(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName)" async defer></script>

<div id="grecaptcha_element" data-sitekey="@(Configuration.GetValue<string>("GoogleRecaptchaSiteKey"))"></div>
<div id="grecaptcha_element" data-sitekey="@(Configuration.GetRequiredValue<string>("GoogleRecaptchaSiteKey"))"></div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

namespace Microsoft.Extensions.Configuration;

Expand All @@ -20,41 +21,42 @@ public static class IConfigurationBuilderExtensions
/// </summary>
public static void AddClientConfigurations(this IConfigurationBuilder builder)
{
var tempConfigBuilder = new ConfigurationBuilder();

var clientCoreAssembly = Assembly.Load("Boilerplate.Client.Core");
IConfigurationBuilder configBuilder = AppPlatform.IsBrowser ? new WebAssemblyHostConfiguration() : new ConfigurationBuilder();

var sharedAssembly = Assembly.Load("Boilerplate.Shared");

tempConfigBuilder.AddJsonStream(sharedAssembly.GetManifestResourceStream("Boilerplate.Shared.appsettings.json")!);
configBuilder.AddJsonStream(sharedAssembly.GetManifestResourceStream("Boilerplate.Shared.appsettings.json")!);

var envSharedAppSettings = sharedAssembly.GetManifestResourceStream($"Boilerplate.Shared.appsettings.{AppEnvironment.Current}.json");
if (envSharedAppSettings != null)
{
tempConfigBuilder.AddJsonStream(envSharedAppSettings);
configBuilder.AddJsonStream(envSharedAppSettings);
}

tempConfigBuilder.AddJsonStream(clientCoreAssembly.GetManifestResourceStream("Boilerplate.Client.Core.appsettings.json")!);
var clientCoreAssembly = Assembly.Load("Boilerplate.Client.Core");

configBuilder.AddJsonStream(clientCoreAssembly.GetManifestResourceStream("Boilerplate.Client.Core.appsettings.json")!);

var envClientCoreAppSettings = clientCoreAssembly.GetManifestResourceStream($"Boilerplate.Client.Core.appsettings.{AppEnvironment.Current}.json");
if (envClientCoreAppSettings != null)
{
tempConfigBuilder.AddJsonStream(envClientCoreAppSettings);
configBuilder.AddJsonStream(envClientCoreAppSettings);
}

tempConfigBuilder.Sources.AddRange(builder.Sources);

var sourcesField = builder.GetType().GetField("_sources", BindingFlags.NonPublic | BindingFlags.Instance)!;

if (sourcesField.FieldType == typeof(List<IConfigurationSource>))

if (AppPlatform.IsBrowser)
{
var providersField = builder.GetType().GetField("_providers", BindingFlags.NonPublic | BindingFlags.Instance)!;
providersField.SetValue(builder, (((IConfigurationRoot)configBuilder).Providers).Union(((IConfigurationRoot)builder).Providers).ToList());
}
else if (AppPlatform.IsBlazorHybrid)
{
sourcesField.SetValue(builder, tempConfigBuilder.Sources);
builder.Sources.AddRange(configBuilder.Sources);
}
else
{
var configurationManager = new ConfigurationManager();
configurationManager.Sources.AddRange(tempConfigBuilder.Sources);
sourcesField.SetValue(builder, configurationManager.Sources);
var originalSources = builder.Sources.ToList();
builder.Sources.Clear();
builder.Sources.AddRange(configBuilder.Sources.Union(originalSources));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//+:cnd:noEmit
using System.Net.Http;
using Boilerplate.Client.Windows.Services;
using Microsoft.Extensions.Logging;
using Boilerplate.Client.Windows.Services;
using Boilerplate.Client.Windows.Configuration;

namespace Boilerplate.Client.Windows;

Expand Down Expand Up @@ -70,6 +71,10 @@ public static void ConfigureServices(this IServiceCollection services)
//#endif
});

services.AddOptions<WindowsUpdateSettings>()
.Bind(configuration.GetRequiredSection(nameof(WindowsUpdateSettings)))
.ValidateOnStart();

services.AddClientCoreProjectServices();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Boilerplate.Client.Windows.Configuration;
using Microsoft.Extensions.Options;
using Velopack;

namespace Boilerplate.Client.Windows;
Expand Down Expand Up @@ -27,7 +28,7 @@ public static void Main(string[] args)
try
{
var services = await App.Current.Dispatcher.InvokeAsync(() => ((MainWindow)App.Current.MainWindow).BlazorWebView.Services);
var windowsUpdateSettings = services.GetRequiredService<IConfiguration>().GetSection("WindowsUpdateSettings")?.Get<WindowsUpdateSettings>();
var windowsUpdateSettings = services.GetRequiredService<IOptionsSnapshot<WindowsUpdateSettings>>().Value;
if (windowsUpdateSettings?.FilesUrl is null)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private static void AddIdentity(WebApplicationBuilder builder)
var identityOptions = appSettings.Identity;

var certificatePath = Path.Combine(AppContext.BaseDirectory, "DataProtectionCertificate.pfx");
var certificate = new X509Certificate2(certificatePath, configuration["DataProtectionCertificatePassword"], OperatingSystem.IsWindows() ? X509KeyStorageFlags.EphemeralKeySet : X509KeyStorageFlags.DefaultKeySet);
var certificate = new X509Certificate2(certificatePath, configuration.GetRequiredValue<string>("DataProtectionCertificatePassword"), OperatingSystem.IsWindows() ? X509KeyStorageFlags.EphemeralKeySet : X509KeyStorageFlags.DefaultKeySet);

bool isTestCertificate = certificate.Thumbprint is "55140A8C935AB5202949071E5781E6946CD60606"; // The default test certificate is still in use
if (isTestCertificate && env.IsDevelopment() is false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

<ItemGroup>
<Content Remove="appsettings*.json" />
<EmbeddedResource Include="appsettings*.json" />
<EmbeddedResource Include="appsettings*.json"/>
<EmbeddedResource Update="appsettings.*.json">
<DependentUpon>appsettings.json</DependentUpon>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,20 @@ public static class IConfigurationBuilderExtensions
/// </summary>
public static void AddSharedConfigurations(this IConfigurationBuilder builder)
{
var tempConfigBuilder = new ConfigurationBuilder();
IConfigurationBuilder configBuilder = new ConfigurationBuilder();

var sharedAssembly = Assembly.Load("Boilerplate.Shared");

tempConfigBuilder.AddJsonStream(sharedAssembly.GetManifestResourceStream("Boilerplate.Shared.appsettings.json")!);
configBuilder.AddJsonStream(sharedAssembly.GetManifestResourceStream("Boilerplate.Shared.appsettings.json")!);

var envSharedAppSettings = sharedAssembly.GetManifestResourceStream($"Boilerplate.Shared.appsettings.{AppEnvironment.Current}.json");
if (envSharedAppSettings != null)
{
tempConfigBuilder.AddJsonStream(envSharedAppSettings);
configBuilder.AddJsonStream(envSharedAppSettings);
}

tempConfigBuilder.Sources.AddRange(builder.Sources);

var sourcesField = builder.GetType().GetField("_sources", BindingFlags.NonPublic | BindingFlags.Instance)!;

var configurationManager = new ConfigurationManager();
configurationManager.Sources.AddRange(tempConfigBuilder.Sources);
sourcesField.SetValue(builder, configurationManager.Sources);
var originalSources = builder.Sources.ToList();
builder.Sources.Clear();
builder.Sources.AddRange(configBuilder.Sources.Union(originalSources));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
namespace Microsoft.Extensions.Configuration;
public static class IConfigurationExtensions
{
public static T GetRequiredValue<T>(this IConfiguration configuration, string name)
{
return (configuration ?? throw new ArgumentNullException(nameof(configuration)))
.GetValue<T>(name ?? throw new ArgumentNullException(nameof(name))) ?? throw new InvalidOperationException($"{name} config could not be found");
}

public static string GetServerAddress(this IConfiguration configuration)
{
var serverAddress = configuration.GetValue("ServerAddress", defaultValue: "/")!;
var serverAddress = configuration.GetRequiredValue<string>("ServerAddress");

if (AppEnvironment.IsDev() &&
serverAddress.Contains("localhost", StringComparison.InvariantCultureIgnoreCase) &&
Expand Down

0 comments on commit 8e76ece

Please sign in to comment.