ASP.NET Upgrade from Beta 1 to Beta 2: Part 3
July 21st, 2005There were two annoyances which caused headaches initially in this migration. After beating my head into the keyboard I came up with some answers.
The first annoyance was the fact that I could no longer access ConnectionStrings values from outside the web project. The access settings on the properties and methods were changed to allow only objects inside the web project to access those configuration settings. It was a problem for this project because I isolate all of the database work into a class library in a single assembly. And I want that assembly to have no dependencies on System.Web, only System.Data.
I resolved the problem by creating a sort of bridge between the web project and the library. Using the Provider concept which Microsoft is using in ASP.NET 2.0 I created an interface called ConnectionStringProvider in the class library and implemented it in the web project with a class called WebConnectionStringProvider. Also in that class library I created an object called DomainConfiguration with a Property called ConnectionStringProvider. In the New constructor I have the following code. Initially I planned to call it with the Application_Start event but I had trouble with that event happening too late. (Note: this is VB.NET code)
DomainConfiguration.ConnectionStringProvider = _ New WebConnectionStringProvider
To get the connections strings, I use this code...
Dim settings As ConnectionStringSettings = _
WebConfigurationManager.ConnectionStrings(name)
If Not settings Is Nothing Then
Return settings.ConnectionString()
Else
Throw New ApplicationException("Connection string not found: " _
+ name)
End If
The second annoyance I resolved in the upgrade to Beta 2 is the fact that ConfigurationSettings is now replaced by ConfigurationManager. That should be easy enough to change, but VS.NET was complaining that ConfigurationManager was not defined. (What do you mean it is not defined!?)
I later discovered the problem, but I think it would not happen with a new Beta 2 web project. The reference the System.Configuration was not associated with the project. I had to manually add the reference so that VS.NET could find ConfigurationManager. Normally you would expect System.Configuration would be included as a default for a web project. In this case that did not happen. Once this change was made the project compiled cleanly and I went about the rest of my day.
