MEF零件配置,存放在哪里?

发布于 2024-09-30 10:48:15 字数 296 浏览 0 评论 0原文

ASP.NET.NET 4.0MEF 中,我将所有部分放在一个文件夹中,并使用 DirectoryCatalog 导入它们>。一切都很好。部分部件有相关配置。我不想将它们放在 web.config 中。也许一个好的方法是在该部分旁边添加一个 config 文件,并在末尾添加一个 .config

存储零件配置的最佳方式是什么?

In ASP.NET, .NET 4.0, MEF, I put all parts in a folder and importing them using DirectoryCatalog. Everything is fine. Some of part have related configurations. I don't want put them in web.config. Maybe a good approach be a config file just beside the part with a .config added to the end.

What is the best way for storing part configuration ?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪失控 2024-10-07 10:48:15

我能够为每个 DLL 创建一个单独的配置文件,并成功读取密钥。但是当我尝试创建自定义配置部分时,我无法从 DLL 的应用程序配置中读取。它总是想从 MEF Consumer exe 中读取。

以下是从使用的 dll 自己的应用程序配置中读取的代码

var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location); 
    return appConfig.AppSettings.Settings["SomeKeyName"].Value;  

由于我无法从自定义配置部分中读取内容,因此我最终使用 xml 并将自定义配置部分序列化为对象。由于您只是获取邮件服务器信息,因此使用 app.config 不会有任何问题。

I was able to create a separate config file for each DLL and successfully was able to read the keys. But when I tried to create a custom config section, I was not able to read from the DLL's app config. It always wanted to read from the MEF Consumer exe.

Here is the code to read from the consumed dll's own app config

var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location); 
    return appConfig.AppSettings.Settings["SomeKeyName"].Value;  

Since I was not able to read from a custom config section, I ended up using xml and serializing the custom configuration section to an object. Since you are just getting the mail server info you will have no problem using app.config.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文