MEF parts configuration, where to store?

烂漫一生 提交于 2019-12-06 03:46:12

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/4078563/mef-parts-configuration-where-to-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!