c# inject appsetting code example

Example 1: appsettings in console application c#

using System;
using Microsoft.Extensions.Configuration;

namespace DiConsoleApp
{
    public class SomeService : ISomeService
    {
        IConfiguration configuration;

        public SomeService(IConfiguration configuration)
        {
            this.configuration = configuration;    
        }

        public void DoProcess()
        {
            var value = configuration["SomeKey"];
            Console.WriteLine("Value from the Config is: " + value);
        }
    }
}

Example 2: appsettings in console application c#

{
    "SomeKey": "This is from Config!"
}