views:

206

answers:

5

I'm trying to create Global.asax in a Winform. I could do it in ASP.NET, but i couldn't find a way for Windows Application. Any help will be appreciated.

I have a singleton class called DataAccessLayer, i need to instantiate it once only, so i can call its method/properties anywhere in the application easily.

+6  A: 

That's because a Global.asax is designed only for an Asp.NET application. What are you trying to accomplish? We may have an alternative solution for you.

Just guessing, but one of the more popular uses of a global.asax is for application-wide exception handling. If that's your aim, you should see this previous post. Otherwise, please ask a new question with details on what you are trying to accomplish.

David Stratton
"one of the more popular uses of a global.asax is for application-wide."Yes this is kind of what i'm looking for. I need to instantiate DataAccessLayer object in the Global.asax so i don't have to create the DataAccessLayer object in every method. I initiate it once in Global.asax and then in the Businesss object class i call the wanted methods by using dot.
peace
For what you're trying to accomplish, @Joe Enos's answer is good.
David Stratton
+2  A: 

You cannot add a Global.asax to a winform application in the same way that you cannot add an aspx page it. They are parts of webforms.

The purpose of Global.asax is to define application and session events and objects. You can do this from the Main() method of you winform application.

Oded
"Main() method of you winform application."Aha, ok...
peace
A: 

My DataAccessLayer class is set as Singleton (sealed)

peace
`sealed` doesn't makes your class a Singleton but rather makes it non-inheritable
Regent
You shouldn't add comments like this as an answer. Use the comment button beneath your question and every answer (if you don't see the `add comment` button, you don't have enough reputation yet).
voyager
He doesn't have enough reputation to comment.
Aren
@Aren B: you don't need reputation to comment on your own questions or any of its answers.
Sandor Drieënhuizen
+2  A: 

If you just need a global access point, put in a Global.cs normal class, and put your static references in there.

Joe Enos
A: 

Sounds like you want to load global variables and then perform and unload when the program ends.
Use a static class like Oded mentioned.
You can also look into the Application.ApplicationExit Event for an equivalend to Application_End and Session_End http://msdn.microsoft.com/en-us/library/system.windows.forms.application.applicationexit.aspx

Brian