c# - Load implementation based on a parameter -


i have problem:

in c# i'm making program should connect various databases (sqlite, sql server compact, ms access, etc). set in app.config parameter called "dbtype" (it 1 sqllite, 2 sql server compact, 3 ms access, etc.). parameter should changed user while program running, dropdown menu or this.

then program reads parameter , creates instance of implementation of database interface (idatabase) corresponds chosen database.

the code is:

class objectdatabasecreator     {         protected objectdatabase objectdb;         protected object objectdao;         protected int dbtype;         protected string dbname;          public objectdatabasecreator()         {         }          public objectdatabasecreator(string dbname)         {             this.dbtype = objectconfiguration.getdbtype();             this.dbname = dbname;         }          public objectdatabase getobjectdatabase()         {             //1 - sqlite; 2-sqlserver compact; 3-sqlserver express; 4-ms access               switch (dbtype)             {                   case 1:                     objectdb = new objectdatabase(new database_impl_1(dbname));                     break;                  case 2:                     objectdb = new objectdatabase(new database_impl_2(dbname));                     break;                  case 3:                     objectdb = new objectdatabase(new database_impl_3(dbname));                     break;                  case 4:                     objectdb = new objectdatabase(new database_impl_4(dbname));                     break;             }              return objectdb;         }         } 

well, seems works know if there possibility make easier add databases, mean, if there db should modify class, recompile, etc.

and how instantiate other implementation bll classes, let's person, customer, etc ? these changes , should add more classes.

thanks, trav

take @ mef... can useful because add notion of catalog. defines many idatabaseimplemention class want in assemblies located in folder, , mef allow "import" found classes.

mef included in .net framework (from v4), there many other framework can job.


Comments

Popular posts from this blog

jQuery clickable div with working mailto link inside -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -