利用标准 IConfiguration 行为基于运行时值覆盖 Appsettings.json 配置

发布于 2025-01-16 22:12:23 字数 322 浏览 1 评论 0原文

我想知道是否有一种方法可以利用标准 IConfiguration、IOption 覆盖功能来根据每个请求评估的数据覆盖 appsettings 配置值。

我有一个多租户应用程序,我希望整个平台有一些通用的默认配置值,但我还希望能够为每个租户甚至每个租户内的每个“部门”覆盖其中的一些值。

我将租户和部门的配置以 Json 形式存储在数据库中,并且在解析租户后,我希望能够根据请求将 appsettings 值与数据库中的值合并/覆盖。

显然我可以手动完成,但我想知道是否可以集成和利用标准 asp.net core IConfiguration/IOption 已经工作的合并/覆盖功能。

I'm wondering if there's a way to exploit the standard IConfiguration, IOption override functionality to override appsettings configuration values based on per request evaluated data.

I have a multi tenant application and I'd like to have some common default configuration values for the whole platform but I'd like also to be able to override some of them per Tenant or even per "Division" inside each tenant.

I store the Tenant's and Division's configurations as Json in the database and I'd like to be able to merge/override the appsettings values with those in the db per request once resolved the tenant.

Obviously I can do it manually but I'm wondering if I can integrate and exploit the already working merging/override functionality of the standard asp.net core IConfiguration/IOption.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文