IConfiguration does not contain a definition for GetValue

断了今生、忘了曾经 提交于 2019-12-06 21:58:00

问题


After moving a class through projects one of the IConfiguration methods, GetValue<T> stopped working. The usage is like this:

using Newtonsoft.Json;
using System;
using System.Net;
using System.Text;
using Microsoft.Extensions.Configuration;

namespace Company.Project.Services
{
    public class MyService
    {
        private readonly IConfiguration _configuration;

        public string BaseUri => _configuration.GetValue<string>("ApiSettings:ApiName:Uri") + "/";

        public MyService(
            IConfiguration configuration
        )
        {
            _configuration = configuration;
        }
    }
}

回答1:


Just install Microsoft.Extensions.Configuration.Binder and the method will be available.

The reason is that GetValue<T> is an extension method and does not exists directly in the IConfiguration interface.



来源:https://stackoverflow.com/questions/54767718/iconfiguration-does-not-contain-a-definition-for-getvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!