我遇到了这个错误,但是无论如何都无法理解。
尝试激活“Microsoft.FeatureManagement.ConfigurationFeatureSettingsProvider”时,无法解析类型为“Microsoft.Extensions.Configuration.IConfiguration”的服务。
这是一个简单的 .net core 2.2 控制台应用程序,并添加了以下 NuGet 包。
- Microsoft.Extensions.Configuration.Json
- Microsoft.Extensions.DependencyInjection
- Microsoft.FeatureManagement
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FeatureManagement;
using Microsoft.FeatureManagement.FeatureFilters;
namespace ConfigurationConsoleApp
{
class Program
{
static async Task Main(string[] args)
{
const string FeatureName = "Beta";
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
var services = new ServiceCollection();
services.AddSingleton(configuration).AddFeatureManagement().AddFeatureFilter<PercentageFilter>().AddFeatureFilter<AccountIdFilter>();
var serviceProvider = services.BuildServiceProvider();
var featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
var enabled = await featureManager.IsEnabledAsync(FeatureName);
Console.WriteLine($"The {FeatureName} feature is {(enabled ? "enabled" : "disabled")} ");
}
}
}
// The following are the command for the packages.
dotnet add package Microsoft.Extensions.Configuration.Json --version 2.1.1
dotnet add package Microsoft.Extensions.DependencyInjection --version 2.1.1
dotnet add package Microsoft.FeatureManagement --version 2.0.0-preview-010610001-1263