IConfiguration不包含GetValue的定义 [英] IConfiguration does not contain a definition for GetValue

查看:675
本文介绍了IConfiguration不包含GetValue的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在类中移动IConfiguration方法之一后,GetValue<T>停止工作.用法是这样的:

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;
        }
    }
}

推荐答案

只需安装Microsoft.Extensions.Configuration.Binder,该方法将可用.

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

原因是GetValue<T>

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

这篇关于IConfiguration不包含GetValue的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆