Aguacongas.DynamicConfiguration.Razor 2.0.0

dotnet add package Aguacongas.DynamicConfiguration.Razor --version 2.0.0
NuGet\Install-Package Aguacongas.DynamicConfiguration.Razor -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aguacongas.DynamicConfiguration.Razor" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aguacongas.DynamicConfiguration.Razor --version 2.0.0
#r "nuget: Aguacongas.DynamicConfiguration.Razor, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Aguacongas.DynamicConfiguration.Razor as a Cake Addin
#addin nuget:?package=Aguacongas.DynamicConfiguration.Razor&version=2.0.0

// Install Aguacongas.DynamicConfiguration.Razor as a Cake Tool
#tool nuget:?package=Aguacongas.DynamicConfiguration.Razor&version=2.0.0

Aguacongas.DynamicConfiguration.Razor

Razor components to configure your .NET application dymamically.

Usage

Setup

Using a Blazor application.

You need to define a class to bind to your whole configuration:

/// <summary>
/// Defines the configuration we can override
/// </summary>
public class ServerConfig
{
    /// <summary>
    /// Gets or sets the reverse proxy configuration
    /// </summary>
    public ProxyConfig? ReverseProxy { get; set; }

    /// <summary>
    /// Gets or sets the logging configuration
    /// </summary>
    public LoggingConfig? Logging { get; set; }
}

This class must be shared by the blazor application and the web API.

The Blazor app appsettings.json should contains a SettingsOptions:

{
  "SettingsOptions": {
    "TypeName": "Yarp.Configuration.Model.ServerConfig, Yarp.Configuration",
    "ApiUrl": "https://localhost:7035/api/configuration"
  }
}

The Program.cs can look like:

using Aguacongas.DynamicConfiguration.Razor;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Yarp.AdminBlazorApp;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
var rootComponents = builder.RootComponents;
rootComponents.Add<App>("#app");
rootComponents.Add<HeadOutlet>("head::after");

var services = builder.Services;
var configuration = builder.Configuration;

// The Settings components requires authentication.
// Update this code with the remote authorization service of your choice
services.AddOidcAuthentication(options => 
{
    options.ProviderOptions.Authority = builder.HostEnvironment.BaseAddress;
});

// Configure the httpClientBuilder to meet your requirement by adding an authorization message handler.
var httpClientBuilder = services.AddConfigurationService(configuration.GetSection("SettingsOptions"));

services.AddAuthorizationCore(options =>
{
    // The Settings component requires the policiy, DYNAMIC_CONFIGURATION_WRITTER_POLICY
    // In this sample this policy requires nothing, all users can save data.
    // You should update this code to meet your requirement.
    options.AddPolicy(Settings.DYNAMIC_CONFIGURATION_WRITTER_POLICY,
        builder => builder.RequireAssertion(context => true));
});
await builder.Build().RunAsync();

Review the Yarp.AdminBlazorApp sample.

Localization

The library contains localized string resources used by components :

key value
Create Créer
delete supprimer
Edit Editer
key clé
Save Sauver

Only emglish and french resources are provided at the moments, but you can provide your resources in yours languages by implementing ISettingsLocalizer and providing the implementation in the DI:

public class SettingsLocalizer : ISettingsLocalizer
{
    private readonly IStringLocalizer<Settings> _stringLocalizer;

    public SettingsLocalizer(IStringLocalizer<Settings> stringLocalizer)
    {
        _stringLocalizer = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer));
    }

    public LocalizedString this[string name] => _stringLocalizer[name];
}
 services.AddScoped<ISettingsLocalizer, SettingsLocalizer>();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Aguacongas.DynamicConfiguration.Razor:

Package Downloads
Aguacongas.TheIdServer.BlazorApp.Infrastructure

TheIdServer administration application models, services, validators and extensions.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Aguacongas.DynamicConfiguration.Razor:

Repository Stars
Aguafrommars/TheIdServer
OpenID/Connect, OAuth2, WS-Federation and SAML 2.0 server based on Duende IdentityServer and ITFoxtec Identity SAML 2.0 with its admin UI
Version Downloads Last updated
2.0.0 2,146 11/24/2023
2.0.0-preview1-0080 1,017 10/4/2023
1.0.1 12,688 2/2/2023
1.0.1-preview1-0044 385 2/2/2023
1.0.1-preview1-0037 392 2/1/2023
1.0.0 99,991 12/25/2021
1.0.0-preview1-0057 460 12/23/2021
1.0.0-preview1-0056 428 12/23/2021