Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inheritance for application class
Message
De
23/12/2005 04:31:22
 
 
À
22/12/2005 20:16:03
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01079712
Message ID:
01080446
Vues:
10
Hi,

One approach :
Sub-class myApplication and adapt as ness.
Use Sub Main() as startup and instantiate your sub-classed myApplication there.
Wire up the events as needed.

Here's a C# example:
http://blogs.msdn.com/pedrosilva/archive/2005/3/9.aspx

HTH,
Viv

>Based on my research all week long on this, it seems the subclassing of the application class in the .NET Framework is extremely difficult. All seems to relate to the My namespace and its components such as MyApplication, MyUser and so on. Microsoft has done it in a way that is it extremely difficult to sub class it as if there wouldn't be a need for it. Someone out there should realize that no matter how smart the design of the .NET Framework is done, there will always be needs for developers to sub class, in this case, the application class.
>
>I know people like Kevin McNeish and others have done superb frameworks and they probably have found a way to do it. But, it is not obvious. Many documents I have read mention about the same thing. You just can't sub class the My namespace as you would sub class something else. This is because these My namespace components are currently implemented as individual classes rather than as namespaces. Some individuals also mentioned that we should not subclass the My namespace. Well, how about that! It's like I would buy a car and I wouldn't be allowed to modify it. I guess I wouldn't have one to drive right now in such circumstances.
>
>IAC, this is extremely frustrating and irritating. I have tried over 80 approaches this week to find what is the proper way to do it. I wasn't even able to find one. All the exemples I have seen mention how to do it from the project itself. So, basically, if you would like to show a message box, for exemple, to tell the user that the application already has an instance running, when the user is trying to launch the application a second time, you would have to do it in the My namespace inside the project. Very well, that works good and really good. But, I have to cut that code from ApplicationEvents.vb and paste that code in all my projects. That means if I would like to enhance that, I would have to redo it all over again in all the projects.
>
>I wasn't able to find one sample out there, and not even one mention about that ability, which is to sub class the My.MyApplication class in a framework, such as the Framework.dll file I am adding as a reference to my all my projects, so I can benefit of my framework.
>
>Here is an example. This code is from ApplicationEvents.vb in one of my projects:
>
>
>Namespace My
>
>    ' The following events are availble for MyApplication:
>    '
>    ' Startup: Raised when the application starts, before the startup form is created.
>    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
>    ' UnhandledException: Raised if the application encounters an unhandled exception.
>    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
>    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
>    Partial Friend Class MyApplication
>
>        Private Sub App_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
>            Framework.App.Initialize()
>        End Sub
>
>    End Class
>
>End Namespace
>
>
>As you can see, I have sub classed the Startup() event to execute my own initialization routine. I need that. But, this means I have to add this insertion in ApplicationEvents.vb for all my projects. This doesn't make any sense. I want it out of there. I want it in my Framework.dll in a way that the My namespace of every project would be able to recognize as a sub class of its Startup() event. So, if I ever enhance this logic, in Framework.DLL, it will be good for all other projects I have without changing anything in each of them.
>
>If anyone would like to comment on this and/or would like to provide solutions or potential solutions, that would be greatly appreciated.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform