Re: Runtime Class Registration in VB.Net
Geoff Taylor <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <007001c924a4$ae9cadf0$0bd609d0$@com> |
I did something much like that recently, so here's one way that will meet some of your needs: * Define an attribute class that specifies, say, the feature name and the class type to use. * Set the attribute to be used at the assembly level. * In your application, iterate through all DLLs in your bin folder, load the DLL, and look to see if it has any of the assembly-level attributes. * If it has, put the feature name and class type into whatever data structure you use for this kind of thing. This works OK in practice. You can quite legitimately change any of the steps though (use an interface instead of an attribute, put the attribute on the class itself, use an abstract base class). One general problem is that you'll usually require the target classes to have a parameterless constructor (or at least a constructor with known parameters). Unfortunately this isn't something that can be enforced at compile time via an interface or base class. I can go into more detail, if it'll help. Good luck, Geoff > -----Original Message----- > From: Discussion of advanced .NET topics. [mailto:ADVANCED- > [email protected]] On Behalf Of Greg Rothlander > Sent: 02 October 2008 16:21 > To: [email protected] > Subject: [ADVANCED-DOTNET] Runtime Class Registration in VB.Net > > I'm working on a compiler and I want to modify some of the > initialization/loading process a bit to make it more maintainable and > extendable, and I'm running into one problem. Here's the basic idea. > > > > Back in VB5/6 I worked on an application for law enforcement and the > military where a particular office wanted say 10 of say 20 features. > Each > feature had a price tag and the client only purchased the ones they > needed. > What we did for that was to create a DLL folder and when a client > purchased > 10 of the 20, we placed the 10 they wanted in the folder and burned the > installation CD. When the user went to install, the installation would > place that folder in the executable directory. When the user executed > the > application, a startup process would read through that folder and > register > each DLL. Then menu's and other structures were dynamically generated > at > startup based on what was registered, licensed, and what was found in > that > DLL folder. If a client purchased an additional module to the > application, > we would send them an installation CD with only that DLL and a license > key. > They would then run the install and that DLL would then be copied to > the DLL > folder, and the license key would update the security as needed to make > sure > they had a license to run that DLL. In the end, what we were doing was > allowing runtime loading of the DLLs that the application was using, > and > that's basically what I want to do know. But the techniques that we > used > back 15 years ago do not seem to apply to .Net and I'm guessing there > has to > be a new and better way to do this. Maybe I'm not thinking here and > there > is an easy and common way to support this... I think that is the case. > I > think I'm just overlooking something simple here. > > > > You see this in application such as PhotoShop. When then start up, you > watch a number of DLLs load on the splash screen. That is basically > what I > want to do. Dynamically load up 300 to 400 classes at start up. > > > > What I want to do is to create lots of small classes (300 to 400 of > them), > then at startup I want to dynamically load them to be used by the > compiler. > When I want to add a new class I can just create a standalone class and > compile it and drop it into the folder. The next time the application > starts up, it will pick up the new class and use it. > > > > What this allows is end-user extensions to the compiler, or to override > compiler processes without having to modify the base code. > > > > Any thoughts, suggestions, or ideas would be very much appreciated. > > > > Best regards, > > Jon Rothlander > > > > > =================================== > View archives and manage your subscription(s) at > http://peach.ease.lsoft.com/archives =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives