从内存中的 XML 字符串读取 EntLib 4.1 配置
我想在我当前的项目中使用 EntLib 4.1,特别是 Unity 1.2 和 VAB。我的应用程序是 SaaS 应用程序,因此我决定将特定于租户的配置文件存储在数据库中,以便在租户登录时加载。这些文件包括 VAB 配置和 Unity 配置,以及其他特定于租户的设置。
我找不到任何实用的方法来简单地使用 XML 字符串作为 VAB 的配置信息。
我首先认为我必须创建 IConfigurationSource 的自定义实现,但后来我意识到我必须复制 FileConfigurationSource 类中已有的解析逻辑。
下一个想法是,我可以创建一个从 FileConfigurationSource 派生的新类,然后使用新类作为代理来传递配置信息而不是带有文件路径的字符串,但我不知道如何重写文件加载的地方。
我查看了 SqlConfigurationSource QuickStart 示例,但这又不是我认为我真正需要的。
I'd like to use the EntLib 4.1 in my current project, specifically Unity 1.2 and the VAB. My application is an SaaS application, so I've made a decision to store tenant-specific configuration files in the database, to be loaded on tenant sign-in. These files include the VAB config and Unity config, as well as other tenant-specific settings.
I can't find any practical way to simply use an XML string as my configuration info for the VAB.
I first thought that I'd have to create a custom implementation of IConfigurationSource, but then I realized that I would have to duplicate the parsing logic already present in the FileConfigurationSource class.
The next thought was that I could create a new class that derives from FileConfigurationSource, and just use the new class as a proxy to pass in the config info instead of a string with the file path, but I couldn't see how to override the place where the file is loaded.
I checked out the SqlConfigurationSource QuickStart sample, but that again is not really what I think I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我为解决此问题而提出的解决方案:
我创建了一个新类 XmlConfigurationSource,它派生自 IConfigurationSource:
XmlValidatorSettings 类是实现此功能的关键。这是一个从 ValidationSettings 派生的非常简单的类:
要使用此代码,您需要引用 EntLib 公共和验证 DLL。希望其他人能从中受益!
Here is the solution that I came up with to solve this issue:
I created a new class, XmlConfigurationSource, that derived from IConfigurationSource:
The XmlValidatorSettings class was sort of the key to get this working. It's a very simple class deriving from ValidationSettings:
To use this code you'll need to reference the EntLib common and validation DLL's. Hope other people benefit from this!