Managing web.config appSettings I wanted a pattern to manage web.config appsettings. I want to be able to have a default setting if the config setting was missing. I also wanted the check for the value in the config file to happen only once, not each time the the value is retrieved.

Public NotInheritable Class ExternalReportRequestBL

    ''' &lt;summary&gt;
    ''' The default value for max number of request attempts
    ''' &lt;/summary&gt;
    ''' &lt;remarks&gt;&lt;/remarks&gt;
    Private Shared _ReportRequestMaxExecuteAttemptDefault As Integer

    Shared Sub New()
        If Not Integer.TryParse(ConfigurationManager.AppSettings("ReportRequestMaxExecuteAttempt"), ExternalReportRequestBL._ReportRequestMaxExecuteAttemptDefault) Then
            _ReportRequestMaxExecuteAttemptDefault = 10
        End If
    End Sub

    Friend Shared ReadOnly Property MaxNumberOfTries As Integer
        Get
            Return ExternalReportRequestBL._ReportRequestMaxExecuteAttemptDefault
        End Get
    End Property
End Class


Now, I can access the variable from anywhere in the assembly:

ExternalReportRequestBL.MaxNumberOfTries


What are your thoughts?
Integer.TryParse will overwrite the value of that shared property with 0 if the value is not there. Use something like this instead:

Shared Sub New()
    Dim parsed As Integer
    If Integer.TryParse(ConfigurationManager.AppSettings("ReportRequestMaxExecuteAttempt"), parsed) Then
        _ReportRequestMaxExecuteAttemptDefault = parsed
    End If
End Sub