Managed Extensibility Framework (MEF) vs. Composite UI Application Block (CAB)

北城以北 提交于 2019-12-04 08:18:11

I may be wrong but I don't think that MEF has any event brokering. It is a general composition engine similar to ioc containers but intended for a more general plug-in and application extensibility solution. CAB and Prism on the other hand are UI frameworks that allow composite applications that're made up of UI components. Since UI components will most likely need to communicate with each other and respond to activities in other UI components, the underlying framework needs to provide a mechanism for eventing (pub/sub) between UI components.

If you are using MEF with WPF and the MVVM pattern, then your parts typically export ViewModel classes and View classes (e.g. DataTemplates, etc.). Your View binds to the ViewModel and uses dependency properties and commands to communicate back and forth. Therefore, if Part A needs to communicate with Part B, then Part A can Import a reference to Part B's ViewModel and they can make method calls back and forth. Part A can also register event handlers for Part B's events, etc.

MEF does not include an eventing mechanism, however you can use Prism's event aggregator with MEF. I did a post on this here.

http://codebetter.com/blogs/glenn.block/archive/2009/02/23/event-aggregation-with-mef-with-and-without-eventaggregator.aspx

The way it works is you basically export Prism's composite event classes.

HTH Glenn

I concur with Scott. The "generic" pub/sub model seems interesting but seldom have I had a need for it. If I want a decoupled message, with MEF I simply define a contract IMessage and then export an implementation, then import wherever I need it. If it's a strongly-typed message, I'll import the exact part I need to speak with and directly message it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!