I created my own CMS for my own use. currently, I already launch 3 websites using my CMS. and will keep adding.
since all the websites always use the same version of my CMS, I just need to create one administration site to rule them all.
I use Subsonic 2.x for data access layer. in administration website, I have to put all connectionStrings
<SubSonicService defaultProvider="firstSql">
<providers>
<clear/>
<add name="firstSql" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="first" generatedNamespace="firstSql"/>
<add name="secondSql" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="second" generatedNamespace="second"/>
<add name="thirdSql" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="third" generatedNamespace="thirdSql"/>
</providers>
</SubSonicService>
<connectionStrings>
<clear/>
<add name="first" connectionString="Data Source=123.123.12.3;Initial Catalog=first;User ID=first;Password=first" providerName="System.Data.SqlClient"/>
<add name="second" connectionString="Data Source=123.123.12.3;Initial Catalog=second;User ID=second;Password=second" providerName="System.Data.SqlClient"/>
<add name="third" connectionString="Data Source=123.123.12.3;Initial Catalog=third;User ID=third;Password=third" providerName="System.Data.SqlClient"/>
</connectionStrings>
here is the ugly code
switch(sitename){
case "first":
var comment1 = new firstSql.Comment(id);
comment1.Accepted = true;
comment1.Save();
break;
case "second":
var comment2 = new secondSql.Comment(id);
comment2.Accepted = true;
comment2.Save();
break;
case "third":
var comment3 = new thirdSql.Comment(id);
comment3.Accepted = true;
comment3.Save();
break;
}
I'm looking for a way to make it like this
/* some magic to dynamically change the connection string */
cmsSql.ConnectionString( getConnectionString(sitename) );
var comment = new cmsSql.Comment(id);
comment.Accepted = true;
comment.Save();
Is there any ORM solution that support this?
Or,
do you know any workaround to do it with current ORM (Subsonic 2.x) ?
UPDATE: I add one more example
cmsSql.ConnectionString( DB_ConString_WebsiteABC );
var comment = new cmsSql.Comment(id);
comment.Accepted = true;
comment.Save();
/* some magic to dynamically change the connection string */
cmsSql.ConnectionString( DB_ConString_AnotherWebsiteThatSimilarToABC );
var comment = new cmsSql.Comment(id);
comment.Accepted = true;
comment.Save(); // saved to another database
If you only need to manage the CMS for one site at once, I would use a single SubSonic provider, and change the static DefaultConnectionString property, as per this example:
http://www.stevetrefethen.com/blog/SettingSubsonicsconnectionstringatruntime.aspx