question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to read the configuration from a separate file?

See original GitHub issue

Now the configuration is in the appsettings.json file in the section: “Finbuckle:MultiTenant:Stores:ConfigurationStore”

Is it possible to use a separate file for the “Finbuckle:MultiTenant:Stores:ConfigurationStore”?

I pack my app to the Docker image and it may be useful to locate the config file in a mapped folder to provide user possibility to edit the configuration.

I have made: moved the section “Finbuckle:MultiTenant:Stores:ConfigurationStore” to the appsettings2.json file

           var config = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .AddJsonFile(@"..\Config\appsettings2.json", optional: true)
                .Build();

services.AddMultiTenant<DerivedTenantInfo>()
                    .WithStore<ConfigurationStore<DerivedTenantInfo>>(ServiceLifetime.Singleton)
                    .WithHostStrategy(tenantSettings.HostTemplate)
                    .WithPerTenantOptions<S3ConfigOptions>((options, tenantInfo) =>
                    {
                        options.ServiceURL = tenantInfo.S3ServiceURL;
                    });


But when I run the app it gives an exception:

Finbuckle.MultiTenant.MultiTenantException: Section name provided to the Configuration Store is invalid.
   at Finbuckle.MultiTenant.Stores.ConfigurationStore`1..ctor(IConfiguration configuration, String sectionName)
   at Finbuckle.MultiTenant.Stores.ConfigurationStore`1..ctor(IConfiguration configuration)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewTriesToCodecommented, Jun 5, 2020

Hello @Oleg26Dev Thanks for the details. Two things:

  1. The path to your json file should be @".\Config\appsettings2.json" (only a single leading dot) based on your folder configuration.

  2. You create a config in Main, but that is a totally separate configuration from the one ASP.NET Core creates and uses. To add your json file to the built-in configuration call ConfigureAppConfiguration as a part of your CreateHostBuilder method:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration(config =>
                {
                    config.AddJsonFile(@"./Config/appsettings2.json");
                    //Console.WriteLine(....);
                })
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

Give that a try, that should get you going. I was able to run the app like that.

0reactions
stale[bot]commented, Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading settings from separate config file - asp.net
I used a configuration helper in a shared DLL, and an app.config file in the DLL that uses the Settings.Properties.Default stuff by editing...
Read more >
How to: Read application settings - .NET Framework
NET Framework project, right-click on your project in Solution Explorer and choose Add > New Item. Choose the Application Configuration File ...
Read more >
Store custom information from a configuration file - C# | ...
In the Name text box, type App.config, and then select Add. You can use an application configuration file to collect custom application settings...
Read more >
Read a configuration file
The task is to read a configuration file in standard configuration file format, and set variables accordingly. ... You are encouraged to solve...
Read more >
From Novice to Expert: How to Write a Configuration file ...
You can use FORCE_ENV_FOR_DYNACONF to let the application read a different section in your settings file, or use monkeypatch to replace a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found