开发者

How would I give a delegate infinite life the same way as a proxy when doing cross-app-domain development?

开发者 https://www.devze.com 2023-02-22 12:55 出处:网络
Background I developed a custom plugin architecture using a derivation of the Observe开发者_Python百科r/Event Pattern and bits and pieces of code from the following:

Background

I developed a custom plugin architecture using a derivation of the Observe开发者_Python百科r/Event Pattern and bits and pieces of code from the following:

Code Project: Plugin Manager

Microsoft: AppDomains

Daniel Soltyka: Simple Plugin

I had an issue in the past. Each plugin is loaded in it's own app domain so that they cannot see each other nor can they see things in the main app domain (we have proprietary data in our application we do not want plugin developers to see). A proxy is created with each new app domain/plugin in order to communicate with the plugin from the main app. The issue was that the proxy became disconnected after 5 minutes or so. This was easily solved by overriding the InitializeLifetimeService() method and returning null (reference).

The Problem

The issue now is on the other side of things. I am "registering" callback functions on the plugin side by sending delegates from the main app side to each plugin. The plugins can then call these delegates which will call the functions in the main app. The delegates, though, apparently get disconnected just like the proxies in the above explanation.

I read this on SO and the ClientSponsor.Register() method sounds great, but it needs a "MarshalByRefObject" as parameter. Mine are delegates, so no dice.

I want to find a way to keep my main app delegates connected across app domains the way the plugin proxies are.

Any ideas?


OK, I figured out how to get around this issue. What I did was I changed my approach and created a separate proxy object derived from MarshalByRefObject and I overloaded that same InitializeLifetimeService() function so that it would not get disconnected. I then have that be the proxy used by the plugins to communicate with the main application.

So now, instead of sending delegates from the main app to each plugin to use I send that proxy object and each plugin communicates through that. Sort of like exchanging phone numbers. The plugins send the main application their proxy and the main app then sends each plugin its proxy.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号