Question about loading class elements dynamically

A

Anthony P.

Hello Everyone,

I'm totally lost and I hope someone can help me out or point me to
something that can. Here's the deal:

I have an application that will implement a 'plugin' archetecture of
sorts. The application requires the user to fill out various forms.
Each agency that we deploy the application to will have different
forms and those forms will change over time. If we build each form
into the application through hard code, changing, adding, or removing
forms requires that the entire application be recompiled and
reinstalled.

So what I'm doing is designing the forms as part of a class library.
So let's take filling out a log for example. I'll create a new class
library and then add three Windows forms to it. Let's call them
frmStep1, frmStep2, and frmStep3 (all which pass data amongst
themselves). I build my class library and let's say that is called
LogFormLib.dll. What I need to happen is that I can distribute this
dll to my users, have them drop it in a special directory and have my
application automatically pick it up and make it available via the
menu system. This way, new forms can be added by simply distributing
a new DLL that contains the code.

I know this sounds easy, and I'm sure it is somewhat, but I am totally
lost. How can I do this? Are there any tutorials?

Thanks!
Anthony
 
M

Michel Posseth [MCP]

Easyest way in my opinion would be that you define a generic interface for
the class in the by you descibed situatien if lots of changes might happen
and you do not want to redeploy , i guess a invocation and comunication
interface to your main app would be the way to go

If you have defined this interface you can invoke anny plugin dll that
contains this interface , so in basic the once defined invocation interface
can never change cause then you need to redeploy your app however everything
that is beyond the interface can be changed to anything you like

to help you get started investigate "reflection" techniques

HTH

Michel Posseth [MCP]
 
A

Anthony P.

Thank you Michael. This seems a bit complex but exactly what I need!
So, I know how I'm going to spend my Sunday! lol

Thanks Again,
Anthony
 
A

Anthony P.

Michael,

I thought everything was going to be fine but I'm already confused so
let me ask a few pointed questions if you don't mind. I think if I get
these answered, I will be well on my way to properly using reflections
and building my plugin archetcture:

1. Do I define my interface in a seperate class file that will be
included in my main applications project?

2. What kinds of informatition do I need to put in my interface class?

For example:
Any given plugin will contain a bunch of Windows Forms that will
interact with each other AND the main application that loads them. So
let's say I have a menu item that loads form1 from an external dll
file. Form1 will have multiple controls on it that will take data from
the user and then call from2 (also contained in this external dll).

The only cavaet is that each plug-in will need to access variables
definied in the main application as Friends.

3. If I understand this correctly, I will basically be doing three
things:
1. Creating my main application.
2. Creating a SEPERATE class library that defines an interface
(this dll will be distributed with my main app)
3. Create seperate plugins that implement that interface.

I suppose I am maybe getting a small understanding of how this is
going to work but I still need a small bit of directlion.

Thanks in Advance
Anthony
 
M

Michel Posseth [MCP]

Hello Anthony

see comments inline


Anthony P. said:
Michael,

I thought everything was going to be fine but I'm already confused so
let me ask a few pointed questions if you don't mind. I think if I get
these answered, I will be well on my way to properly using reflections
and building my plugin archetcture:

1. Do I define my interface in a seperate class file that will be
included in my main applications project?

No it should be in a seperate dll the interface must be included with the
forms dll and with your main executable so it would be the
best way to create a seperate dll for this purpose
2. What kinds of informatition do I need to put in my interface class?

You can put in everything you like however be aware that the interface is
the only way through wich your main executable and the forms dll can
comunicate
So depending on your basic needs of data you would define properties and
methods and if you like even events ofcourse the interface should be the
same for all forms , so if you need in one form more return data as another
i would try to find a generic way ( parameter arrays , dataset etc etc )
For example:
Any given plugin will contain a bunch of Windows Forms that will
interact with each other AND the main application that loads them. So
let's say I have a menu item that loads form1 from an external dll
file. Form1 will have multiple controls on it that will take data from
the user and then call from2 (also contained in this external dll).

The only cavaet is that each plug-in will need to access variables
definied in the main application as Friends.

Well i do not see anny problem for that this is possible through the
interface just define an interface with properties however these properties
must be declared Public instead of Friend

3. If I understand this correctly, I will basically be doing three
things:
1. Creating my main application. Yes :)
2. Creating a SEPERATE class library that defines an interface Yes
(this dll will be distributed with my main app)
Yes the interface must be contained in a seperate dll as it must be
referenced in the main exe and in the plugin dll`s
3. Create seperate plugins that implement that interface.
Yes

I suppose I am maybe getting a small understanding of how this is
going to work but I still need a small bit of directlion.
Well with reflection you have the advantage that you have the ability to
extend your application or even let other developers create extensions for
your application
as long as they implement your interface correctly it should work .

You could for instance define a standard directory where your app will
search on startup for dll`s that implement the interface , then you put
these in a menu structure wich you dynamicly generate and invoke the dll
when clicked on in your menu

Thanks in Advance
Anthony

If you need an example ( i am afraid quick and dirty cause i am a bit
bussy at the moment ) feel free to contact me

regards

Michel Posseth [MCP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top