不用引入任何命名空间,Configuration自带
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
namespace ConsoleCore
{
class Program
{
static void Main(string[] args)
{
var initData = new List<KeyValuePair<string, string>>();
initData.Add(new KeyValuePair<string, string>("username", "abcd"));
IConfiguration configuration = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory)
.AddInMemoryCollection(initData)
.Build();
var username = configuration["username"];
Console.WriteLine(username);
}
}
}