帮助我设计封装数据库的架构(也许是 DI/IoC?)

发布于 2024-08-08 02:11:04 字数 714 浏览 3 评论 0原文

我正在构建一个 Windows 窗体应用程序,它进行一些依赖于 3 个不同数据库的分析。两个实际上是地理数据库 (ESRI),一个是标准 CRUD 类型的信息存储库。我们分别将它们称为 GeoRefDatabase、GeoResultDatabase 和 RulesDatabase。将会有不同类型的分析类(最终可能多达 10 个)需要访问所有 3 个数据库。

  • GeoRefDatabase 是集中式的并且永远不会移动。它将需要一个连接字符串。
  • GeoResultDatabase 是存储某些分析输出的位置。它的“连接字符串”和物理位置可能在运行时(每次调用分析时)发生变化。结果是会出现多个这样的实例。
  • 规则数据库是集中的并且永远不会移动。它将需要一个连接字符串。

例如,我希望能够调用类似的内容:

 var dbRef = GetDbRef();
 var dbRules = GetDbRules();
 var dbResult = GetDbResult( myLocation );

 var z = AnalysisTypeA( dbRef, dbResult, dbRules );

现在提出问题......

  1. 我如何封装这些数据库?我已经开始熟悉 IoC/DI 并且有点倾向于它,但我不确定最好的方法应该是什么。
  2. 存储连接字符串和类似信息的最佳方法是什么?应用程序配置?

I'm building a Windows-forms application that does some analysis that depends on 3 different databases. Two are actually geographic databases (ESRI) and one is a standard CRUD-type repository of information. Let's call them GeoRefDatabase, GeoResultDatabase, and RulesDatabase, respectively. There will be different types of analysis classes (maybe eventually as many as 10) that need to access all 3 databases.

  • GeoRefDatabase is centralized and never moves. It will require a connection string.
  • GeoResultDatabase is where some output of the analysis will be stored. It's "connection string" and physical location could vary at run time (each time an analysis is called). The result is there will be multiple instances of these.
  • RulesDatabase is centralized and never moves. It will require a connection string.

So for example, I want to be able call something like:

 var dbRef = GetDbRef();
 var dbRules = GetDbRules();
 var dbResult = GetDbResult( myLocation );

 var z = AnalysisTypeA( dbRef, dbResult, dbRules );

Now for the questions .....

  1. How do I encapsulate these databases? I've been getting familiar with IoC/DI and am kind of leaning toward that, but I'm not sure what the best approach should be.
  2. What is the best method for storing the connection strings and similar information? App.confg?

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

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

发布评论

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

评论(1

水波映月 2024-08-15 02:11:04

对于不移动的两个数据库,它可能是 DI 的候选者,因为它不会经常移动,但在某些时候可能会移动。

如何在运行时确定要访问哪个其他数据库?

如果您提前知道连接字符串,然后将它们放入字符串数组中,并将其注入,那么您可以选择使用数组中的三个或四个连接字符串中的哪一个。您可能需要两个数组,一个是连接字符串,另一个是数据库名称,因此您可以将它们放入哈希图中。

将这些放入 App.config 是一个可能的选择,至少根据我的经验。

For the two databases that aren't moving it could be a candidate for DI, as it won't move often, but, at some point might.

How do you determine at runtime which of the other databases to go to?

If you know the connection strings ahead of time then put them into an array of strings, and inject that in, then you can pick which of the three or four connection strings in the array to use. You may want to have two arrays, one is the connection strings, the other is the names of the databases, so you can put these into a hashmap.

Putting these into App.config would be a likely candidate, at least in my experience.

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