Question Regarding Plugin Architecture

J

Joseph Ferris

I am working on a Web Application that can dynamically load
UserControls, a la a plugin style system. When I create any new
controls within the project, all is fine.

What my question is, would be how might I be able to allow someone to
create a plugin that would not require that I rebuild the application -
or is it even possible? Right now, this is what I have:

A BasePage class that inherits from System.Web.UI.Page that is used to
extend the Page object for extended rendering functionality.

A BaseControl class that inherits from System.Web.UI.UserControl that
is used to extend the UserControl object for specific rendering
capabilities that are used by all plugins.

I have a page that inherits from BasePage. To it, I've added a
PlaceHolder control. Then on Page_Load, I simply use LoadControl to
load the specific control and add it to the PlaceHolder. My ultimate
goal would be to build up a repository of these objects in a database
so that I could configure certain controls to be used in certain
situations. Basically, it is a CMS-type application.

Like I mentioned, as long as the control exists in the main project,
all is well. But assume that a third party wants to develop a plugin.
I don't want to give access to the code to that person, for obvious
reasons.

Are my options limited to adding the DLL from the plugin to the /bin
folder of the main application? After I do that, how do I get the
application to recongize the DLL? If I put them in a subfolder
structure to keep them organized, does this impact anything in regards
to the ability to load the control?

Thank you, in advance, for any input.

Joseph
 
J

Joseph Ferris

I have made some progress. What I am doing now, instead of
LoadControl, is I am creating a reference to the Assembly by using
Assembly.LoadFrom(). I then cast it to the correct control type and
assign it to the control collection of a placeholder on the calling
page. This is what I have in my Page_Load on the ASPX page:

Dim MyPlaceHolder As PlaceHolder =
CType(Me.FindControl("TemplateHolder"), PlaceHolder)

If Not MyPlaceHolder Is Nothing Then

Dim DynamicASM As [Assembly]
DynamicASM =
DynamicASM.LoadFrom(Server.MapPath("./New/bin/New.dll"))

Dim ControlInstance As MyLib.Page.Controls.Template =
CType(DynamicASM.CreateInstance("New.Index"),
MyLib.Page.Controls.Template)

MyPlaceHolder.Controls.Add(ControlInstance)

ControlInstance.TestOutput()

End If

The TestOutput() method is defined in the base control instance, and
outputs "Base" to the screen when called, if it is not overriden. I
override it in the derived instance to display "Derived". When I run
the above code, it displays "Derived". But now, my new problem...

Any content in the derived control is not displayed. For example, I
added a table in the designer and recompiled. The instance I create
from the assembly is displaying "Derived", so it is creating it. The
events of the derived control are also being hit correctly, if I add
breakpoints in the debugger. I just can't get the table to show. I am
assuming that something is happening in LoadControl that this approach
does not do.

Does anyone have any idea as to might what be going on, or have a
better approach to this? I am feeling a little lost at the moment.
;-)

Thanks!

Joseph
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top