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 add section in appsettings.json

See original GitHub issue

I want to add some configurations to appsettings.json, and I need to read it in project xxx.ApplicationService and project xxx.Core. var configuration = AppConfigurations.Get(Web.WebContentDirectoryFinder.CalculateContentRootFolder()); Logger.Info(configuration.GetConnectionString("Default")); Logger.Info(configuration.GetSection("SmsSettingNames:AliyunSms:ServiceUrl").Value); I can get the connection string, but section is null.

appsettings.json { "ConnectionStrings": { "Default": "Data Source=(LocalDB)\\ProjectsV13;Initial Catalog=AbpZeroTemplate; Integrated Security=True" }, "SmsSettingNames": { "AliyunSms": { "ServiceUrl": "dysmsapi.aliyuncs.com", "AppKey": "XXXXXXXX", "AppSecret": "XXXXXXX", "DefaultFreeSignName": "XX", "DefaultSmsTemplateCode": "SMS_XXXX" } } What should I do

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ismcagdascommented, May 15, 2018

@rqx110 we don’t ASP.NET does, it is copied to bin folder when you run the app.

@LGinC you can try like this;

Define an interface in your Core project like below;

public interface IAppConfigurationAccessor
{
	IConfigurationRoot Configuration { get; }
}

Then create it’s implementation in your Web project like this;

public class AppConfigurationAccessor: IAppConfigurationAccessor, ISingletonDependency
{
	public IConfigurationRoot Configuration { get; }

	public AppConfigurationAccessor(IHostingEnvironment env)
	{
		Configuration = env.GetAppConfiguration();
	}
}

After all, try injecting IAppConfigurationAccessor and access the config.

0reactions
LGinCcommented, May 15, 2018

@rqx110 检查了,保存了,重启了,没用啊

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add custom section to .NET Core local.settings.json
I'm writing my first Azure function (based on .NET Core 2.x), and I'm struggling to extend the app settings with my custom mapping...
Read more >
Accessing Custom Configuration Section in ASP.Net Core
Assume we have a config section for mail settings called “MailConfiguration”, which I configured like below in appsettings.json,
Read more >
Reading Values From Appsettings.json In ASP.NET Core
In the first method, we are getting our section from the configuration object. Inside this, we are getting another section that contains the ......
Read more >
Application Settings (appsettings.json)
All of the application's settings are contained in a file named appsettings.json. Any changes to the appsettings.json file will require ...
Read more >
Configuration in ASP.NET Core
Settings files, such as appsettings.json; Environment variables ... section and add it to the dependency injection service container.
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