如何从一个.dll访问应用程序的配置? [英] How to access app configuration from a .dll?

查看:162
本文介绍了如何从一个.dll访问应用程序的配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近打破了我的winform应用程序中的一个.dll的一部分。一些班级在该DLL 想获取/存储用户设置。 这些类只是用VS生成的设置文件,所以它只是做了 Properties.Settings.Default.SomeSetting =变种; Properties.Settings.Default.Save()

I recently broke out a part of my winform app in a .dll. Some of the classes in that dll wants fetch/store user settings. The classes just used the VS generated Settings file so it just did Properties.Settings.Default.SomeSetting = var;Properties.Settings.Default.Save() etc.

什么是我的选择,现在我感动的是code出一个类库/ .DLL?

What are my options now that I moved that code out to a class library/.dll ?

推荐答案

的托管应用程序应该处理的接口配置文件,而不是DLL。无论是

The hosting application should handle the interface to the config file, not the DLL. Either

  1. 传递任何需要读取/在DLL中修改参数设置,或

  1. Pass whatever settings need to be read/modified within the DLL as parameters, or

传入的设置,可以由DLL被修饰,一个名称 - 值集合和任何变化由该DLL作出保存到集合时控制返回到调用应用程序

Pass in a name-value collection of settings that can be modified by the DLL, and save whatever changes are made by the DLL to the collection when control returns to the calling application.

这在原则上是从一个分层应用程序的业务层移除数据库接口,并将其封装到一个数据层相似。

This is similar in principle to removing a database interface from the business layer of a tiered application and encapsulating it into a data layer.

这篇关于如何从一个.dll访问应用程序的配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆