官术网_书友最值得收藏!

Summary

Because JSON is the standard nowadays, we should stick with the JSON provider and enable the reloading of the configuration upon changes. We should add the common file first, and then optional overrides for each of the different environments (beware the order in which you add each source). We learned how the default configuration of ASP.NET Core already loads JSON files, including different ones for the different environments.

We then saw how to use configuration sections to better organize the settings, and we also looked at using POCO wrappers for them.

So, this made us ponder whether we should use IOptions<T> or our own POCO classes to inject configuration values. Well, if you don't want to pollute your classes or assemblies with references to .NET Core configuration packages, you should stick to your POCO classes. We're not too worried about this, so we recommend keeping the interface wrappers.

We will use IOptionsSnapshot<T> instead of IOptions<T> so that we always get the latest version of the configuration settings.

After this, we looked at feature toggling, to quickly enable or disable features that are just on or off.

In this chapter, we saw the many ways in which we can provide configuration to an ASP.NET Core application. We learned how to build a simple provider that takes configuration from the Windows Registry. We then discussed the many ways in which we can inject configuration settings using the built-in dependency injection framework, and how to be notified of changes in the configuration sources.

主站蜘蛛池模板: 邛崃市| 潼南县| 漳平市| 泸西县| 大石桥市| 韶关市| 攀枝花市| 天长市| 加查县| 藁城市| 成安县| 平山县| 甘肃省| 大兴区| 堆龙德庆县| 印江| 双江| 元氏县| 宜宾市| 长岛县| 达州市| 沭阳县| 和平区| 共和县| 南城县| 乌兰察布市| 兴城市| 永川市| 竹溪县| 乌拉特中旗| 揭阳市| 建平县| 奉节县| 同仁县| 桃园县| 海口市| 馆陶县| 调兵山市| 黑水县| 镇康县| 广宗县|