【问题标题】:Caliburn.Micro. Automatically call eventaggregator.Subscribe() for IHandle implementors with MEFCaliburn.Micro。使用 MEF 为 IHandle 实现者自动调用 eventtaggregator.Subscribe()
【发布时间】:2011-10-24 08:18:52
【问题描述】:

在 Caliburn.Micro 文档中,作者提到了这种可能性:

文档链接

IHandle inherits from a marker interface IHandle. This allows the use of casting to determine if an object instance subscribes to any events. This enables simple auto-subscribing if you integrate with an IoC container. Most IoC containers (including the SimpleContainer) provide a hook for being called when a new instance is created. Simply wire for your container’s callback, inspect the instance being created to see if it implement IHandle, and if it does, call Subscribe on the event aggregator.

如何使用 MEF 实现这一目标?

这个问题和Caliburn.Micro. Automatically call eventaggregator.Subscribe() for IHandle implementors with Autofac一样

那么与描述的 AutoSubscribeHandersModule 类似的功能如何在 MEF 中实现?

【问题讨论】:

    标签: mef caliburn.micro


    【解决方案1】:

    我在这里写了一篇关于如何在 Caliburn Micro 中使用 MEF 为事件聚合器自动连接的博客; http://www.kjetilk.com/2011/10/auto-wiring-eventaggregator.html.

    简而言之;您需要添加 MEFContrib (nuget -> Install-Package MefContrib),实现订阅任何 IHandle 实例的 IExportedValueInterceptor,并使用引导程序中的 InterceptionCatalog 将拦截器插入 MEF 创建管道。

    【讨论】:

      【解决方案2】:

      查看 MEFContrib 的 InterceptingCatalog。只需按照参考文章中的说明放置 IHandle 而不是 IStartable。

      【讨论】:

        猜你喜欢
        • 2011-10-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多