创建基于插件的WebApp [英] Creating a plug-in based WebApp

查看:66
本文介绍了创建基于插件的WebApp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在创建一个CMS,我希望使用不同的

插件来处理不同类型的内容。

我真正想要的是能够在不重新启动应用程序的情况下即时加载/卸载插件




我做的是创建一个加载插件的AppDomain和

一切都很棒,直到我试图传递域名之间的其他字符串

...


我的插件继承了CompositeControl,这样我就可以轻松加载.ascx文件

来显示插件中的不同对话框和数据,然后我做了一个

placeHolder.Controls.Add(插件);在我的webform上显示插件数据。

问题是,由于CompositeControl不可序列化,我无法在

AppDomains上传输插件。


我试图让我的基类继承ISerializable,现在我没有得到

''不再支持序列化''错误,但现在它抱怨

当我试图显示内容时它找不到我插件的组装。


我的AppDomains看起来像这样:


PrimaryDomain

CMSCore

PlugInBase


OtherDomain

PlugInBase

StaticPage


我的主域名只知道PlugInBase类实现

所有常见的公共方法我需要,但它总是抱怨

StaticPage程序集。


我希望我有点清楚我正在尝试做什么任何人都可能
对我能做什么有任何建议。


提前致谢

/ Mats

Hi,
I''m creating a CMS that I would like to be plug-in based with different
plugins handling different kinds of content.
What I really want is to be able to load/unload plugins on the fly
without restarting the application.

What I did was to create an AppDomain that loaded the plugins and
everything was great, until I tried to pass something else that strings
between the domains...

My plugins inherit CompositeControl so that I can easily load .ascx file
to display the different dialogs and data in my plugins, I then do a
placeHolder.Controls.Add(plugin); to display the plugin data on my webform.
The problem is that I''m not able to transfer the plugin accross the
AppDomains since CompositeControl isn''t Serializable.

I tried to make my base class inherit ISerializable and now I don''t get
''doesn''t support serialization'' error anymore, but now it complains that
it can''t find the assembly of my plugin when I try to display the contents.

My AppDomains look something like this:

PrimaryDomain
CMSCore
PlugInBase

OtherDomain
PlugInBase
StaticPage

My primary domain just knows about the PlugInBase class which implements
all the common public methods that I need, but it complains about the
StaticPage assembly anyway.

I hope I''m somewhat clear in what I''m trying to do and that anyone might
have any suggestions to what I can do.

Thanks in advance
/Mats

推荐答案

您可以通过引用传递对象,但是因为您已经从CompositeControl继承了
,所以不能直接执行此操作,


你需要在这里使用委托模式,


创建一个涵盖你插件上所有方法的界面,制作

插件实现它


创建另一个继承自MarshalByRefObject的类,使这个

对象也实现你的界面。


类(实现marshalbyrefobject)应该有一个属性

你的插件类型,


然后你需要实现的方法(接口)方法)

只需将这些文件路由到插件(通过属性)


a有点啰嗦但是因为我们不能做多重继承这是一个

解决这个问题的方法,

You can pass the object by reference instead, but as you are already
inheriting from CompositeControl you can''t do this directly,

You will need to use the delegate pattern here,

Create an interface that covers all the methods on your plugin, make
the plugin implement it

Create another class that inherits from MarshalByRefObject, make this
object also implement your interface.

The class (that implements marshalbyrefobject) should have a property
of your plugin type,

then for the methods that you need to implement (interface methods)
simply route these to the plugin (via the property)

a bit long winded but as we can''t do multiple inheritence this is one
way of getting around this,


感谢您的快速回复!


我已经已经完成了这个,但它对我不起作用......问题是我想要将我的控件添加到占位符控件集合中,然后我需要

a直接引用该插件以便我可以添加它。


我的插件使用.ascx文件显示数据而我无法创建

没有访问WebForms上下文的实例(因为我理解它),所以我需要以通常的方式添加插件,

Controls.Add(插件) ;

ga ********** @ gmail.com 写道:
Thanks for the fast reply!

I''ve already done this but it doesn''t work for me... the thing is that I
want to add my control to a placeholders control collection, then I need
a direct reference to the plugin so that I can add it.

My plugin uses .ascx files to display the data and I can''t create an
instance of it without having access to the WebForms context (as I
understand it), so I need to add the plugin the usual way,
Controls.Add(plugin);

ga**********@gmail.com wrote:
你可以通过引用传递对象,但是因为你已经从CompositeControl继承了你不能直接做到这一点,

您需要在此处使用委托模式,

创建一个涵盖所有met的接口点击你的插件,使插件实现它

创建另一个继承MarshalByRefObject的类,使这个
对象也实现你的界面。

该类(实现marshalbyrefobject)应该具有您的插件类型的属性

然后对于您需要实现的方法(接口方法)
简单地将这些属性路由到插件(通过财产)

有点长的啰嗦,但由于我们不能做多重继承,这是解决这个问题的一种方式,
You can pass the object by reference instead, but as you are already
inheriting from CompositeControl you can''t do this directly,

You will need to use the delegate pattern here,

Create an interface that covers all the methods on your plugin, make
the plugin implement it

Create another class that inherits from MarshalByRefObject, make this
object also implement your interface.

The class (that implements marshalbyrefobject) should have a property
of your plugin type,

then for the methods that you need to implement (interface methods)
simply route these to the plugin (via the property)

a bit long winded but as we can''t do multiple inheritence this is one
way of getting around this,






Hi Mats,


多个子域外接程序架构通常用于许多destop

应用程序,对于asp.net场景似乎并不常见。无论如何,基于

我的理解,我们将在这里遇到以下问题:


1.对于ASP.NET的页面处理,它是基于请求/响应。因此,每个

时间在服务器工作线程中处理请求(页面类和其他

控制实例在此服务器管道中构建....),之后

表示,所有页面和控件实例都被销毁,页面内容

正在刷新到客户端....(后来新帖回到服务器导致新的

要构造的工作线程和页面结构.....)。所以我认为我们不应该将这些加载项作为控件来实现,如果是这样的话,我们需要在每个请求中创建

,我也不要我认为ASP.NET页面模型将支持
支持跨appdomain控制通信....所以我们需要将
实现加载项作为单独的compnt类来加载进入

ASP.NET工作进程(在单独的appdomain中)启动时。


2.然后,因为我们在asp中创建了这些加载项appdomains。 net woker进程

(在启动时),我们以后需要做的是与appdomain中的那些

插件进行通信,这是另一个难题。我能得到什么

目前在启动时创建这些加载项实例的代理

时间(就在他们在跨域创建之后)和将这些

代理引用存储在gobal集合中(ApplicationState或Application

Cache ...)。因此,所有后来的请求都可以在事件代码中访问它们....


无论如何,虽然这是可能的,但我真的感到有些紧张,因为

在ASP.NET进程中创建多个子appdomain可能会使它有点不稳定和跨域通信会损害ASP.NET运行时

性能.....


谢谢,


Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)

---------------- ----

|日期:2005年11月23日星期三19:07:04 +0100

|来自:Mats Lycken< Ma *** @ newsgroups.nospam>

|用户代理:Mozilla Thunderbird 1.0.2(Windows / 20050317)

| X-Accept-Language:en-us,en

| MIME版本:1.0

|主题:Re:创建基于插件的WebApp

|参考文献:< u2 ************** @ TK2MSFTNGP12.phx.gbl>

< 11 ************* *********@g14g2000cwa.googlegroups .com>

| In-Reply-To:< 11 ********************** @ g14g2000cwa.googlegroups .com>

|内容类型:text / plain;字符集= ISO-8859-1; format = flowed

|内容传输编码:7位

|消息ID:< O5 ************** @ tk2msftngp13.phx.gbl>

|新闻组:microsoft.public.dotnet.framework.aspnet

| NNTP-Posting-Host:1-1-3-42a.vs.vs.bostream.se 82.182.18.143

|行数:1

|路径:TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl

|外翻:TK2MSFTNGXA02.phx.gbl

microsoft.public.dotnet.framework.aspnet:360511

| X-Tomcat-NG:microsoft.public.dotnet.framework.aspnet

|

|感谢您的快速回复!

|

|我已经做过这件事,但它对我不起作用......事情就是我

|想要将我的控件添加到占位符控件集合中,那么我需要

|直接引用该插件,以便我可以添加它。

|

|我的插件使用.ascx文件显示数据,我不能创建

|它的实例无法访问WebForms上下文(因为我需要按照常规方式添加插件),

| Controls.Add(插件);

|

| ga**********@gmail.com 写道:

| >您可以通过引用传递对象,但是因为您已经是

| >继承自CompositeControl你不能直接这样做,

| >

| >你需要在这里使用委托模式,

| >

| >创建一个涵盖插件上所有方法的界面,制作

| >插件实现它

| >

| >创建另一个继承自MarshalByRefObject的类,使其成为

| >对象也实现你的界面。

| >

| >该类(实现marshalbyrefobject)应该具有属性

| >您的插件类型,

| >

| >那么你需要实现的方法(接口方法)

| >只需将这些路由到插件(通过属性)

| >

| >有点长的啰嗦,但由于我们不能做多重继承,这是一个

| >绕过这个的方式,

| >

|

|

Hi Mats,

The Mutiple subdomain Add-in architecture is ususally used in many destop
application, seems not quite common for asp.net scenario. Anyway, based on
my understanding, we''ll meet the following problem here:

1. For ASP.NET''s page processing, it is request/response based. So each
time a request is processed in a server worker thread( page class and other
control instances are contructed during this server pipeline....) , after
that , all the pages and control instances are destroyed and page content
being flush to clientside.... (later a new post back to server cause a new
worker thread and page structure to be constructed.....). So I think we
should not implement those add-ins as control, if so, we''ll need to create
them in each request, and also I don''t think ASP.NET page model will
support cross appdomain control communication.... So we need to
implement add-in as separate compent classes which will be loaded into
ASP.NET worker process (in separate appdomain ) at startup time .

2. Then, since we create those Add-in appdomains in asp.net woker process
(at startup time), what we need to do later is communicating with those
addins in the appdomain, this is another hard problem. What I can get
currently is creating those add-in instance''s proxies at start up
time(right after they''ve been created in cross domain) and store these
proxy references in a gobal collection (ApplicationState or Application
Cache...). Thus, all the later requests can access them in events code....

Anyway, though this is possible, I really feel a bit nervous on it since
creating multiple sub appdomain in ASP.NET process may make it a bit
unstable and cross domain communication will hurt the ASP.NET runtime
performance .....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Date: Wed, 23 Nov 2005 19:07:04 +0100
| From: Mats Lycken <Ma***@newsgroups.nospam>
| User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
| X-Accept-Language: en-us, en
| MIME-Version: 1.0
| Subject: Re: Creating a plug-in based WebApp
| References: <u2**************@TK2MSFTNGP12.phx.gbl>
<11**********************@g14g2000cwa.googlegroups .com>
| In-Reply-To: <11**********************@g14g2000cwa.googlegroups .com>
| Content-Type: text/plain; charset=ISO-8859-1; format=flowed
| Content-Transfer-Encoding: 7bit
| Message-ID: <O5**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 1-1-3-42a.vs.vs.bostream.se 82.182.18.143
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:360511
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks for the fast reply!
|
| I''ve already done this but it doesn''t work for me... the thing is that I
| want to add my control to a placeholders control collection, then I need
| a direct reference to the plugin so that I can add it.
|
| My plugin uses .ascx files to display the data and I can''t create an
| instance of it without having access to the WebForms context (as I
| understand it), so I need to add the plugin the usual way,
| Controls.Add(plugin);
|
| ga**********@gmail.com wrote:
| > You can pass the object by reference instead, but as you are already
| > inheriting from CompositeControl you can''t do this directly,
| >
| > You will need to use the delegate pattern here,
| >
| > Create an interface that covers all the methods on your plugin, make
| > the plugin implement it
| >
| > Create another class that inherits from MarshalByRefObject, make this
| > object also implement your interface.
| >
| > The class (that implements marshalbyrefobject) should have a property
| > of your plugin type,
| >
| > then for the methods that you need to implement (interface methods)
| > simply route these to the plugin (via the property)
| >
| > a bit long winded but as we can''t do multiple inheritence this is one
| > way of getting around this,
| >
|
|


这篇关于创建基于插件的WebApp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆