Pronunciation / adjective
Bringing something good and unforseen.
    Skip Navigation Links > Component Library > Application Object
   

The Fortunate.Application object controls how other Fortunate Library objects run based on the application object's environment setting. It may be used for both windows development and web development.



 

Fortunate.Application Object

Download the Fortunate Library Here:

Fortunate Library 32bit - Stand-Alone Install

Fortunate Library 64bit - Stand-Alone Install

Fortunate Library Solution - Source Code

The fortunate.application object is used as a way to control what mode an application (web or windows) is in and to control different functionality based on the mode. It may be set to development, localhost, staging, or production.

It is intended to provide an easy way to control an application's behaviour as the application is moved between environments. I have found having this useful since various ways of getting an application's base file path and base url sometimes have hidden bugs. The most reliable way to get the file path or url is by hard coding it. The fortunate.application object makes it easier to switch between environments with these hard coded.

I have also used the fortunate.application object to control other component's behaviours. A good example is the fortunate.errorhandling component which gives different error messages based on the fortunate.application object's environment setting.

Here is an excerpt that shows how to set the fortunate.application environment in a web.config or app.config file:
  1. <appSettings>
  2. <!--Valid Environment Values: Development, Localhost, Production, Staging-->
  3. <add key="ApplicationEnvironment" value="Development"/>
  4. </appSettings>

The fortunate.application object also contains a few properties which may be set once for each environment and then the property corresponding to the correct envrionment setting is delivered when the fortunate.application object is queried for that property. Currently the fortunate.application object contains properties for:

  • The file path for each application environment

  • The base url for each application environment


The way I typically set these is like this:
  1. Private Sub InitializeApplicationObject()
  2. If _ApplicationObject Is Nothing Then
  3. Me._ApplicationObject = New Fortunate.Application
  4. '
  5. 'AboutFortunateApplicationObject
  6. '
  7. Me._ApplicationObject.ApplicationName = "About Fortunate Website"
  8. Me._ApplicationObject.ApplicationType = Fortunate.Application.ApplicationTypes.Internet
  9. Me._ApplicationObject.BaseFilePathDevelopment = ""
  10. Me._ApplicationObject.BaseFilePathLocalhost = "C:\Users\Philosopher\Documents\Visual Studio 2005\Projects\AboutFortunate\AboutFortunateWeb"
  11. Me._ApplicationObject.BaseFilePathProduction = ""
  12. Me._ApplicationObject.BaseFilePathStaging = ""
  13. Me._ApplicationObject.BaseUriDevelopment = "http://development.aboutfortunate.com"
  14. Me._ApplicationObject.BaseUriLocalHost = "http://localhost/AboutFortunateWeb"
  15. Me._ApplicationObject.BaseUriProduction = "http://www.aboutfortunate.com"
  16. Me._ApplicationObject.BaseUriStaging = "http://staging.aboutfortunate.com"
  17. End If
  18. End Sub

The way I've used the fortunate.application object has changed with each .net release. Currently my preferred method for windows applications is to drop the application object directly onto the forms page (in the case of a single form application).

In web applications I used to place the fortunate.application object into the global.asax page and then stored it in an application level variable for retrieval from any page on the site.

But with the advent of master pages I have found the master page to be a much more convenient place to instantiate many of my objects for use on every page.

I have sample code showing my preferred method of using the fortunate.application and fortunate.errorhandling objects within a website's master page on the Error Handling Object Page.
Microsoft Certified Professional   © 2017 Fortunate.  All rights reserved.
contact: justin@aboutfortunate.com