Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

Creating an object that has the entire application scope.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vvenk - 26 Oct 2004 01:37 GMT
Hello:

I am thinking of an object called "user."  This object will be instatntiated
during a login process. But I want to use this to control the behavior of the
application since it will also encapsulate the logged-in user's security
profile.

What is the best strategy for creating one such object?

I initially thought of having a module wherein it is declared public. Even
if I do, I may need to pass in as a parameter by reference to the Login form
and by value to other forms. Would I have to have parameters in the forms'
New subroutine? Or, is there a more elegant way to make this exposed
throughout the application?

Venkat
Tom Shelton - 26 Oct 2004 05:21 GMT
> Hello:
>
[quoted text clipped - 12 lines]
>
> Venkat

You could always create the object as a singleton...

Public Class User
    Private Shared instance As User

    ' Allow no uncontroled instances
    Private Sub New ()
    End Sub

    ' Create a shared constructor - this
    ' will be called sometime before first access
    Shared Sub New ()
        instance = new User ()
    End Sub

    ' do all your properties/methods

    Public Shared Function GetInstance () As User
        Return User.instance
    End Sub
End Class

This is a very simple example - but essentially what this allows is that
anywhere in your code you can say:

Dim currentUser As User = User.GetInstance ()
' Do stuff

And all parts of your program will refere to the single shared instance
of the User class.

Signature

Tom Shelton [MVP]

vvenk - 26 Oct 2004 11:29 GMT
Tom:

Wonderful suggestion. Thanks.

> > Hello:
> >
[quoted text clipped - 43 lines]
> And all parts of your program will refere to the single shared instance
> of the User class.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.