ASP MVC 与带有插件配置文件的 MEF
目前我有一个网络服务,它加载位于其 /plugins 文件夹中的所有插件。现在的问题是每个插件都有自己的一组配置数据,当前已硬编码并隔离到单个类中,但我想将其移至 myplugin.config 文件中。
通常,Web 服务会加载自己的 web.config 文件,但我不确定是否可以让插件使用它们自己的文件。就好像您想象主 Web 服务使用 NHibernate 并对某些任意数据执行 CRUD 操作一样,但其中一个插件使用 MongoDB 添加了一个缓存层,并拥有自己的连接字符串详细信息。因此,MVC Web 服务不应该真正关心这些设置,它应该只是需要读取它们的 MyPlugin。
有什么办法可以做到这一点吗?因为我只是想摆脱在代码中根深蒂固的连接字符串。
Currently I have a web service, which loads up any plugins located within its /plugins folder. Now the problem is that each plugin has its own set of configuration data, currently hardcoded and isolated into a single class, but I want to move this out into a myplugin.config file.
Normally the web service loads up its own web.config file, but I am not sure if I can get the plugins to use their own ones. As if you imagine the main web service uses NHibernate and does CRUD stuff with some arbitrary data, but one of the plugins adds a caching layer using MongoDB and has its own connection string details. So the MVC web service shouldn't really care about these settings, it should just be the MyPlugin which would need to read them.
Is there any way to do this? As I just want to get away from having the connection string ingrained within the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在已经解决了这个问题,一旦我发现如何加载配置文件,我就能够做到这一点,而无需太多工作。
我确保我的配置文件是以通过 MEF 加载的程序集命名的,所以如果我的程序集是:
的配置文件
,然后您将调用:
所以希望这可以帮助某人,因为我花了一段时间才找到这个简单的东西。
I have sorted this problem now, I was able to do it without much work really once I found out how config files could be loaded in.
I made sure my config file was named after the assembly loaded via MEF, so if my assembly was:
You would make a config file named:
then you would call:
So hope this helps someone as it took me a while to find this simple thing out.