Skip to content

Add support for appsettings.json #3446

Closed as not planned
Closed as not planned
@dannyBies

Description

@dannyBies

Description

I would like to have support for appsettings.json so I can use settings configured in this file in my MAUI app.

When this is implemented, adding an appsettings.json file to your MAUI project will automatically load the configuration inside it.

I'm using the following code to workaround this issue.

var builder = MauiApp.CreateBuilder();
            builder
                .RegisterBlazorMauiWebView()
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                })
                .Host
                .ConfigureAppConfiguration((app, config) =>
                {
                    var assembly = typeof(App).GetTypeInfo().Assembly;
                    config.AddJsonFile(new EmbeddedFileProvider(assembly), "appsettings.json", optional: false, false);
                });

Public API Changes

I believe no public API changes are necessary

Intended Use-Case

Currently I'm trying to get my Blazor WebAssembly app to work in .NET MAUI. To make this possible I've created a Razor Class Library that contains all the shared components. In this project I also setup my dependency container which needs access to settings I have configured in an appsettings.json file.

In my Blazor WebAssembly app a call to WebAssemblyHostBuilder.CreateDefault(args); will automatically load the neccessary appsettings.json files. It would be great if the same can be done for MauiApp.CreateBuilder();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions