GAC 中的 .NET 程序集 +配置

发布于 2024-08-26 12:00:04 字数 212 浏览 5 评论 0原文

我有一个 .NET 3.5 程序集(DAL),它通过 Linq2SQL 连接到数据库。 我将此程序集部署在 GAC 中,因为它可供多个业务层使用。

问题是:在开发环境中,我的连接字符串与生产环境中的连接字符串不同。在将程序集部署到产品 GAC 之前,我需要使用适当的连接字符串重新编译它。

有没有什么方法可以允许独立于连接字符串将程序集部署到 GAC(从某些配置中读取该信息)?

I have a .NET 3.5 assembly, a DAL, that connects to a database through Linq2SQL.
I deploy this assembly in the GAC as it can be used by multiple business layers.

The question is: in a dev environment I have a connection string different than the one in the production environment. Before deploying the assembly to the prod GAC I need to recompile it with the appropriate connection string.

Is there any way to allow deploying the assembly to the GAC independently of the connection string, being that info read from some config?

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

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

发布评论

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

评论(5

慵挽 2024-09-02 12:00:04

无论是将程序集部署到 GAC 还是网站的 bin 文件夹中,使用该程序集的应用程序的配置都会覆盖 LinqToSQL 类中的连接。

创建数据上下文时,您应该从配置中传递此连接字符串

It doesn't matter whether you deploy the assembly to the GAC or in the bin folder of a website, the config of the application that uses the assembly is the one that overrides the connection in the LinqToSQL classes.

You should pass this connection string in from the config when you create the data context

因为看清所以看轻 2024-09-02 12:00:04

DAL 是否在某处硬编码了连接字符串?如果是这样,那么这不是可配置部署的最佳选择。如果您有权访问 DAL 代码,请重构它,以便它在构造其任何子类时将连接字符串作为参数。然后,任何使用应用程序都可以使用其配置文件的 connectionStrings 部分来存储连接字符串。这样,您就可以随时更改连接字符串。

Does the DAL have the connection string hardcoded somewhere? If so, that's not the best option for configurable deployment. If you have access to the DAL code, refactor it so that it takes the connection string as a parameter on construction of any of its child classes. Then, any consuming application can use the connectionStrings section of their configuration file to store the connection string. This way, you can change the connection string whenever you like.

野侃 2024-09-02 12:00:04

应该将连接字符串存储在 web/app.config 文件中,并在程序集中引用该配置设置。

连接字符串不应进行硬编码,并且 config 文件具有现有的 connectionStrings 部分用于此目的。

如果您需要保护连接字符串,可以加密本节,但您不应依赖 GAC 中的它作为保护,因为使用 ILDASM 可以轻松查看程序集中的所有字符串(包括连接字符串)。

You should have your connection strings stored in your web/app.config file, and reference that config setting in your assembly.

Connection strings should not be hard coded, and config files have an existing connectionStrings section for this purpose.

If you need to secure your connection string, you can encrypt this section, but you shouldn't rely on it being in the GAC as protection, as it is easy to use ILDASM to see all the strings in an assembly (including connection strings).

内心激荡 2024-09-02 12:00:04

IMO,我认为将环境特定值(例如连接字符串)嵌入到 GAC 程序集(或任何与此相关的程序集)中是错误的。相反,GAC 中的组件应该允许将连接字符串传递给它。

IMO, I think it is a mistake to embed an environment specific value like a connection string into a GAC assembly (or any assembly for that matter). Instead, the component in the GAC should allow for having the connection string passed to it.

浮生面具三千个 2024-09-02 12:00:04

考虑更新您的 MACHINE.CONFIG 文件以添加连接字符串或其他配置部分。这将继承到所有 .NET 应用程序。

Consider updating your MACHINE.CONFIG file to add your connection string or other config section. This will inherit to all .NET apps.

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