Click here to Skip to main content
15,895,709 members
Articles / Web Development / ASP.NET

Customising the default AppSettings and ConnectionStrings Expression Builders

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
25 Mar 2009CPOL4 min read 27.1K   90   14  
Use of Expression Builders in different landscapes (Dev / QA / Prod).
<?xml version="1.0"?>
<configuration>
	<appSettings>
		<add key="ServerRegion{Prod}" value="localhost"/>
		<add key="ServerRegion{Dev}" value="localhostd"/>
		<add key="{Prod}Setting1" value="Setting 1 on Prod"/>
		<add key="{Prod}Setting2" value="Setting 2 on Prod"/>
		<add key="{Dev}Setting1" value="Setting 1 on Dev"/>
		<add key="{Dev}Setting2" value="Setting 2 on Dev"/>
		<add key="abc" value="Can be any"/>
	</appSettings>
	<connectionStrings>
  <add name="{Dev}CS1" connectionString="Dev CS1" providerName="Dev P1" />
  <add name="{Dev}CS2" connectionString="Dev CS2" providerName="Dev P2" />
  <add name="{Prod}CS1" connectionString="Prod CS1" providerName="Prod P1" />
  <add name="{Prod}CS2" connectionString="Prod CS2" providerName="Prod P2" />
  <add name="{Dev}NorthwindConnectionString" connectionString="Data Source=MAIN2008\SQL2005;Initial Catalog=Northwind;Integrated Security=True"  providerName="System.Data.SqlClient" />
	<add name="{Prod}NorthwindConnectionString" connectionString="Data Source=MAIN2008\SQL2005;Initial Catalog=Northwind;Integrated Security=True"  providerName="System.Data.SqlClient" />
	</connectionStrings>
	<system.web>
		<compilation debug="true">
			<expressionBuilders>
				<remove expressionPrefix="AppSettings"/>
				<remove expressionPrefix="ConnectionStrings"/>

				<add expressionPrefix="AppSettings" type="Cottle.IT.ExpressionBuilders.MyAppSettingsExpressionBuilder, Cottle.IT.ExpressionBuilders"/>
				<add expressionPrefix="ConnectionStrings" type="Cottle.IT.ExpressionBuilders.MyConnectionStringsExpressionBuilder, Cottle.IT.ExpressionBuilders"/>
			</expressionBuilders>
		</compilation>
	</system.web>
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
I have been developing applications for almost 30 years - started with early versions of Basic on the Sinclair ZX80, moving up via UK101 and Amstrad to PC. Played with Assembly as well. First big application was for a complete test set, which was written using QuickBasic (all I had available to me). Moved on to a bit of C and C++ (never really got to grips with them) and then 11 years ago, got into Visual Basic/SQL Server and HTML. Moved onto .NET and then in the last few years changed across to C# when the job market indicated that it would be better.
Have now developed quite a few ASP.NET Applications, and along the way have played with WPF, Silverlight and am currently working on an MVC based application.

Comments and Discussions