App.config和类库 [英] App.config and class libraries
问题描述
我正在构建一个类库,并希望在
配置文件中存储连接字符串。
>
我已经读完了,看来这是不可能的,因为通过
设计,类库没有自己的配置文件 - 他们读了
配置文件来自它们所在的应用程序,例如WinForm应用程序
或ASP.NET站点
所以,考虑到这一点,还有另一种解决方案吗?
非常感谢,
CR
Hi,
I am building a class library and want to store a connection string in a
configuration file.
I''ve read around and it appears that this is not possible because "by
design, class libraries don''t have their own config file - they read the
config files from the application they are housed in, such as a WinForm app
or ASP.NET site "
So, with that in mind, is there an alternative solution?
Many thanks,
CR
推荐答案
" CodeRazor" <钴******* @ discussions.microsoft.com>在消息中写道
新闻:8F ********************************** @ microsof t.com ...
"CodeRazor" <Co*******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
我正在构建一个类库,并希望在
配置文件中存储连接字符串。
我已经读完了,看来这是不可能的,因为通过
设计,类库没有自己的配置文件 - 他们从中读取
配置文件它们所在的应用程序,例如WinForm
应用程序
或ASP.NET站点
因此,考虑到这一点,是否有替代解决方案?
Hi,
I am building a class library and want to store a connection string in a
configuration file.
I''ve read around and it appears that this is not possible because "by
design, class libraries don''t have their own config file - they read the
config files from the application they are housed in, such as a WinForm
app
or ASP.NET site "
So, with that in mind, is there an alternative solution?
假设代码在Windows / Web应用程序中使用时才真正使用,所以
使用正在使用你的应用程序的app / web.config文件代码
库
并在那里定义连接字符串?使用注册表?
HTH
AP
诺丁汉 - 英国
Presumeably the code is only of real use when used in a Windows/Web app so
use the app/web.config file of the application that is using your code
library
and define the connection string there? Use the registry?
HTH
AP
Nottingham - UK
" CodeRazor" <钴******* @ discussions.microsoft.com>在消息中写道
新闻:8F ********************************** @ microsof t.com ...
"CodeRazor" <Co*******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
我正在构建一个类库,并希望在
配置文件中存储连接字符串。
我已经读完了,看来这是不可能的,因为通过
设计,类库没有自己的配置文件 - 他们从中读取
配置文件它们所在的应用程序,例如WinForm
应用程序
或ASP.NET站点
因此,考虑到这一点,是否有替代解决方案?
Hi,
I am building a class library and want to store a connection string in a
configuration file.
I''ve read around and it appears that this is not possible because "by
design, class libraries don''t have their own config file - they read the
config files from the application they are housed in, such as a WinForm
app
or ASP.NET site "
So, with that in mind, is there an alternative solution?
假设代码在Windows / Web应用程序中使用时才真正使用,所以
使用正在使用你的应用程序的app / web.config文件代码
库
并在那里定义连接字符串?使用注册表?
HTH
AP
诺丁汉 - 英国
Presumeably the code is only of real use when used in a Windows/Web app so
use the app/web.config file of the application that is using your code
library
and define the connection string there? Use the registry?
HTH
AP
Nottingham - UK
您的.dll(读取.NET代码库)不应该依赖于任何东西。
如果您公开的某个对象需要连接字符串才能工作,那么
应该提供一个属性访问器,以使你的库的用户能够获得/设置字符串。
A .dll应该作为一个黑匣子运作,即你知道你需要把什么放入
,你知道你期望得到什么;任何人使用你的图书馆确实
也不想记得复制配置文件(即使你不想要
这样做)
-
在舌头和笔的所有单词中,最悲伤的是:它可能是
比尔。 Richards @ greyskin .co .uk
http://greyskin.co.uk
" CodeRazor"写道:
Your .dll (read .NET code library) should NOT be dependent upon anything.
If one of the objects you expose needs a connection string to work, you
should provide a property accessor to enable the user of your library to
get/set the string.
A .dll should operate as a "black box", i.e. you know what you need to put
in and you know what you expect to get out; anyone using your library does
not want to have to remember to copy the config file too (even you won''t want
to do that)
--
Of all words of tongue and pen, the saddest are: "It might have been"
Bill.Richards @ greyskin .co .uk
http://greyskin.co.uk
"CodeRazor" wrote:
我正在构建一个类库,并希望在
配置文件中存储连接字符串。
我已经读完了,看来这是不可能的,因为通过
设计,类库没有自己的配置文件 - 他们从中读取
配置文件它们所在的应用程序,例如WinForm应用程序
或ASP.NET站点
因此,考虑到这一点,是否有替代解决方案?
CR
Hi,
I am building a class library and want to store a connection string in a
configuration file.
I''ve read around and it appears that this is not possible because "by
design, class libraries don''t have their own config file - they read the
config files from the application they are housed in, such as a WinForm app
or ASP.NET site "
So, with that in mind, is there an alternative solution?
Many thanks,
CR
这篇关于App.config和类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!