how to get value from appsettings.json

So there are really two ways to go about this. Option 1 : Options Class You have an appsettings.json file : { “myConfiguration”: { “myProperty”: true } } You create a Configuration POCO like so : public class MyConfiguration { public bool MyProperty { get; set; } } In your startup.cs you have something in … Read more

Bind to a value defined in the Settings

First, you need to add a custom XML namespace that will design the namespace where the settings are defined: xmlns:properties=”clr-namespace:TestSettings.Properties” Then, in your XAML file, access the default settings instance using the following syntax: {x:Static properties:Settings.Default} So here is the final result code: <ListBox x:Name=”lb” ItemsSource=”{Binding Source={x:Static properties:Settings.Default}, Path=Names}” /> Source: WPF – How to … Read more

ConfigurationManager.AppSettings – How to modify and save?

I know I’m late ๐Ÿ™‚ But this how i do it: public static void AddOrUpdateAppSettings(string key, string value) { try { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = configFile.AppSettings.Settings; if (settings[key] == null) { settings.Add(key, value); } else { settings[key].Value = value; } configFile.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); } catch (ConfigurationErrorsException) { Console.WriteLine(“Error writing app settings”); } } … Read more

Get ConnectionString from appsettings.json instead of being hardcoded in .NET Core 2.0 App

STEP 1: Include the following in OnConfiguring() protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile(“appsettings.json”) .Build(); optionsBuilder.UseSqlServer(configuration.GetConnectionString(“DefaultConnection”)); } STEP 2: Create appsettings.json: { “ConnectionStrings”: { “DefaultConnection”: “Server=YOURSERVERNAME; Database=YOURDATABASENAME; Trusted_Connection=True; MultipleActiveResultSets=true” } } STEP 3: Hard copy appsettings.json to the correct directory Hard copy appsettings.json.config to the directory specified in the … Read more

Read appsettings json values in .NET Core Test Project

This is based on the blog post Using Configuration files in .NET Core Unit Test Projects (written for .NET Core 1.0). Create (or copy) the appsettings.test.json in the Integration test project root directory, and in properties specify “Build Action” as Content and “Copy if newer” to Output Directory. Note that itโ€™s better to have file … Read more

Automatically set appsettings.json for dev and release environments in asp.net core?

Update for .NET Core 3.0+ You can use CreateDefaultBuilder which will automatically build and pass a configuration object to your startup class: WebHost.CreateDefaultBuilder(args).UseStartup<Startup>(); public class Startup { public Startup(IConfiguration configuration) // automatically injected { Configuration = configuration; } public IConfiguration Configuration { get; } /* … */ } CreateDefaultBuilder automatically includes the appropriate appsettings.Environment.json file … Read more

Opening the Settings app from another app

As mentioned by Karan Dua this is now possible in iOS8 using UIApplicationOpenSettingsURLString see Apple’s Documentation. Example: Swift 4.2 UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) In Swift 3: UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!) In Swift 2: UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!) In Objective-C [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; Prior to iOS 8: You can not. As you said this has been covered many times and that pop up … Read more

Getting value from appsettings.json in .net core

Program and Startup class .NET Core 2.x You don’t need to new IConfiguration in the Startup constructor. Its implementation will be injected by the DI system. // Program.cs public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .Build(); } // Startup.cs public class Startup … Read more