MEF 扩展活动

发布于 2024-12-02 06:01:26 字数 307 浏览 3 评论 0原文

我是 MEF(托管扩展性框架)的新开发人员,并已成功启动并运行示例应用程序,并具有多个扩展。这是一个很好用的框架。

我想做的是实现一个标准事件,可以从每个扩展中引发。例如,在我的主机应用程序中,我将有一个 EventHanlder

Extension_OnLog (字符串消息) //在这里执行一些日志记录。

然后每个扩展都能够引发此事件,该事件在主机应用程序中处理。

//扩展1 RaiseEvent OnLog("这是一些日志记录文本")

我不确定这个的正确术语。有人可以为我指出实现此类事件模型的正确方向吗?

I am a new developer to MEF (Managed Extensibility Framework) and have managed to get a sample application up and running, with several extensions. This is a nice framework to use.

What I am looking to do is to implement a standard event which is available to raise from each extension. For example, in my Host application i would have an EventHanlder

Extension_OnLog (string Message)
//Perform some logging here.

And then each Extension would be able to raise this event, which is handled in the Host Application.

//Extension 1
RaiseEvent OnLog("This is some logging text")

I am not sure of the correct terminology of this. Could someone please point me in the right direction for implementing such an event model.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懵少女 2024-12-09 06:01:26

像这样的事情可以工作:

创建两个接口:

IEventRaiser(将包含 RaiseEvent 函数)

IEvent1(将包含实际事件)

创建一个模块(Event1< /strong>) 它将实现这两​​个接口并导出这两个接口。

您的“扩展”可以导入 IEventRaiser,这将允许它们引发事件。

主机应用程序将导入 IEvent1,这将允许它“订阅”事件。

Something like this can work:

Create two interfaces:

IEventRaiser (which will contain function RaiseEvent)

IEvent1 (which will contain the actual event)

Create a module (Event1) which will implement both the intefaces and will export both the interfaces.

Your "extensions" can import IEventRaiser which will allow them to raise the event.

Host application will import IEvent1 which will allow it to "subscribe" to the event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文