在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
相同那么,如何在MEF中实现所描述的AutoSubscribeHandersModule功能?
答案 0 :(得分:0)
检查MEFContrib的InterceptingCatalog。只需将IHandle代替IStartable,如参考文章中所述。
答案 1 :(得分:0)
我在博客中介绍了如何在Caliburn Micro中使用MEF进行Event Aggregator的自动连接; http://www.kjetilk.com/2011/10/auto-wiring-eventaggregator.html
总之;您需要添加MEFContrib(nuget - > Install-Package MefContrib),实现订阅任何IExportedValueInterceptor
实例的IHandle
,并使用InterceptionCatalog
将拦截器插入MEF创建管道在引导程序中。