The following errors were encountered: Please rectify them and try again.

Hi, I'm Rob. I'm a software developer. I primarily work with C# in my professional life, but my home projects are often PHP and Python based.

If you wish to get in contact, then get in touch via my LinkedIn profile

Latest Blog Post

Using a JSON string as a configuration source for a .NET Core project

I recently had a project at work that I wanted to pass in a JSON string as a means of configuration. There is a .NET package that will read in a JSON file, but not one to read in a string. So below you will find a set of classes I made to take in a JSON string and parse it in to the application config using the Newtonsoft JSON library.

  1. public static class ConfigurationExtensions
  2. {
  3. public static IConfigurationBuilder AddJsonString(this IConfigurationBuilder configurationBuilder, string json)
  4. {
  5. configurationBuilder.Add(new JsonStringConfigurationSource(json));
  6. return configurationBuilder;
  7. }
  8. }
  10. public class JsonStringConfigurationSource : IConfigurationSource
  11. {
  12. private readonly string _json;
  14. public JsonStringConfigurationSource(string json) => _json = json;
  16. public IConfigurationProvider Build(IConfigurationBuilder builder) => new JsonStringConfigurationProvider(_json);
  17. }
  19. public class JsonStringConfigurationProvider : ConfigurationProvider

Posted on Wednesday the 3rd of October 2018