views:

54

answers:

1

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?
A: 

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.

James Black
Q: How do you determine at runtime which of the other databases to go to? A: There user will choose from a list of existing databases or create a new one.
Keith G
So storing them in a hashmap would make sense.
James Black