StrataFrame Forum

Access Business Object Gloabally

http://forum.strataframe.net/Topic5714.aspx

By Tim Dol - 1/10/2007

I have created a business object to access a XML datasource. I can access no problem but I would like to create some type of global reference of the business object within the appMain so I only have to create and fill it once and use it throughout the application. 

Hopefully this makes sense. Right now I find myself having to call the fill method to create the object each time I want to access data, so I thought there may be a more efficient way of doing this.

Thanks 

By Paul Chase - 1/10/2007

Tim,

I just do something like this. Not sure if it is the best way to do it but it works okay for me. I have a common class that has shared property's and methods that I use throughout my application, in this instance to get the office name I would to something like this common.OfficeProfile.OFP_OfficeName

here is an example

Public NotInheritable Class Common

' Hide Constructor so class canot be instaniated

Private Sub New()

End Sub

Private Shared _OfficeProfile As New PayrollBO.BOOfficeProfile

Public Shared ReadOnly Property OfficeProfile() As PayrollBO.BOOfficeProfile

Get

'see if Biz Obj is filled

If _OfficeProfile.Count <= 0 Then

_OfficeProfile.Fill()

End If

Return _OfficeProfile

End Get

End Property

By StrataFrame Team - 1/11/2007

Yep, Paul's got it right.  You can create a "static" class somewhere to house your global variables.  Then, just make the variables (or properties that wrap the variables) public and shared (static) and you'll be able to access them from anywhere within the application.

And in VB, you can even import the class name like this so you can reference the variables without having to type the classname first:

Imports MyRootNamespace.MyStaticClass

By Tim Dol - 1/11/2007

Thanks Paul and Ben, this is exactly what I was looking for.