以下是我在申请中所做的更改.在代码中添加了featuretoggle包.并创建了新的打印类(仅用于示例类)扩展Simplefeaturetoggle.
using featuretoggle; namespace AspDotNetCoreExample.Models { public class Printing : Simplefeaturetoggle {} }
appSettings.json添加了featuretoggle Key,并将其设置为true.因此,Printing类将读取它并启用功能切换.
{ "featuretoggle": { "Printing": "true" } }
** Startup.cs在ConfigureServices方法中注册了我的打印服务.我已将配置文件(appSettings.json)传递给Printing类.
public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json",optional: false,reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json",optional: true) .AddEnvironmentvariables(); Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; } public void ConfigureServices(IServiceCollection services) { // Set provider config so file is read from content root path var provider = new AppSettingsProvider { Configuration = Configuration }; services.Configure<AppSettings(Configuration.GetSection("AppSettings")); services.AddSingleton(new Printing { ToggleValueProvider = provider }); services.AddTransient<IMapper,Mapper>(); // Add framework services. services.AddMvc(); }
namespace STAR.Marketing.Portal.Web { public class Mapper: Mapper { private readonly Printing _print; public Mapper(Printing print) //Dependency Injection to get Printing { _print = print; } public string Enabled() { return _print.FeatureEnabled; // To check the feature is enabled but getting the Error System.FileIOException } } }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。