开发者

MEF parts configuration, where to store?

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 .confi开发者_开发技巧g added to the end.

What is the best way for storing part configuration ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜