Main Site Documentation

Anyone with MEF experience?


#1

As the topic says, anyone here with some MEF experience?


#2

I played with it a little.


#3

I’m looking for some examples on how i can populate the main app’s menu with menuitems from the plugins. Any idea?


#4

I would put a method/property in the interface of the plugin that would return an IEnumerable containing items for the menus. Those items would also implement a common interface or class (IMenuItem). Once you get those items, you create you views and models based on that (wpf or winforms) and that’s it.

interface IPlugin
{
  IEnumerable<IMenuItem> MainMenuItems {get;}
}

interface IMenuItem
{
  string Header {get;}
  etc.
}

#5

@ Eric : could you please send me a mail : becafuel “at” lsp-fr dot com


#6

MEF rocks! Are you looking for specifics about how to implement MEF (attribute syntax) or the best way to implement a dynamic menu (and then MEF it)? godfather’s reply is a good start. I would add that the answer ultimately depends on how your main app menu is built.

For example, I work on a WPF app that uses a custom control to build the menu with a XAML resource file at runtime. Each menu item is bound to a command. Another developer needed a way to add menu items (with commands) to kick off his external tools with context sensitive data from my app, without having to pester me to refactor/rebuild. MEF worked perfectly. He can update his library of menu commands at any time and just drop it into a folder in my app. All we had to do was agree on the interface. Very slick.


#7

Bec a Fuel, Mail sent :wink:


#8

I was working at the end of last year on MEF, too. My goal was dynamic loading of drivers for astronomical software : the client application only has to use a (publicly exposed) “selector” that will load existing drivers of different kinds : focusers, filterwheels, cameras, and so on…

It’s giving something as simple as this (for the client app, that is, because it’s obviously not the case behind the scene…) :

AstroDevicesNet.Repository.Focuser FocuserRepository = new AstroDevicesNet.Repository.Focuser(@ "c:\dev\devtmp\DriversMEF");
AstroDevicesNet.Repository.Camera CameraRepository = new AstroDevicesNet.Repository.Camera(@ "c:\dev\devtmp\DriversMEF");

        ADNFocuser Focuser1;
        ADNCamera Camera1;

        Focuser1 = FocuserRepository.Selector();
        Camera1 = CameraRepository.Selector(@ "\Other directory than default");
		
		Focuser1.Devices[0].Move(10);
		Camera1.ExpTime = 16;
		Camera1.StartExposure();

The code in the attached zip archive is functionnal, although I was still trying different things with it such as concurent accesses to multiple devices inside a single driver. So you may find some unused or not useful code in it.

Link : http://www.lsp-fr.com/astro/mef/AstroDevices.Net.7z

This code is also part of a wider open-source project currently being developped by other friends. So if you use (big) parts of it, it would be nice to quote the “AstroDevices.Net” project. Not a huge text, of course, a single line is enough. :wink:

Notice : since it’s still work in progress, I wanted to keep it private, hence my claim for a mail. But since it’s also an open-source project, I see no real reason to keep it “secret” :hand:


#9

If anyone has any suggestions for resources for learning MEF, please post them. This is one of the technologies I have to learn in the next few weeks. If seems there’s not a single book written on the subject yet so i assume all the knowledge is online.


#10

Don’t know if you have seen this: http://msdn.microsoft.com/en-us/library/dd460648.aspx


#11

I’ve learned it the hard way, by using online examples and all I could find about it on the net ???


#12

I haven’t started down the MEF trail yet but hope to start by mid next week when I finish my current book. Sounds like you guys have already figured it out. So, just wanting to save some time since I’m sure you have already found the best resources :wink:

Thanks, godfather.


#13

hi Ericsan and the other

Concerning MEF, I’ve taking at look at it and use it for a piece of code (can’t publish it because it’s company stuff, sorry)…

The application was a simulation tool.

Our goal was to make almost everypart of the software as a plug-in.

As the main architect for this solution, I choose MEF to achieve this “maybe” more easily than by doing my own plug-in system (I’ve already done that kind of architecture and code before).

To achieve our goal, I defined many kind of plug-in. Some where only “process” plug-in as some where devoted to GUI stuff. Some where both.

The main part of the main software was about the loading of the plug-in and the ability to integrate in the window system of our application what the plug-in could provide.

For instance, we had one interface defining that the plug-in was offering extra menu to be integrated in the application. One method of the plug-in was something like that (pseudo code)

Menu GetPluginMenu();

The main application has only to check if the plug-in was offering such a feature and then get the menu and add it to the main menu.

I’ve also defined interface and plug-in for “Log” system, Simulation Plug-in.

I also defined a “Setting plug-in” which where able to gather the setting of each plug-in and create dynamicaly a form by associating “type” of the setting to display with “controle” to use to do that (I’ve defined a xml file where we could fine the assembly where to get the right controle to display for the right type (could be “base” type or “complexe” type").

By doing so (for the setting plug), we were able to integrate different kind of display for same control just by changing the XML control mapping file and by providing, of course, the assembly containing these special controls.

MEF helped me “a lot” to define the contract and to ease my pain in loading all the plug-in.

This is all I can say about this use of the MEF in a “plug-in” context.

Hope you will find it useful and not to “hard and long” to read.


#14

ianlee74,

I’m working on a personal MEF project and its getting into a fairly useable state. Still need to figure out many things, but if you want, I can host the project on my server for you to download.


#15

The Monz,

thanks for your explanation.


#16

De rien, une fois :slight_smile:


#17

It sounds like MEF is useful. I’m starting a new job in a couple weeks and MEF is one of the techs they said they wanted to implement soon. I don’t really know the details of what they have in mind but I want to get somewhat familiar before I get there.

Eric, that would be awesome. Real world examples are far too rare most of the time. I’d love to look at what you’ve done.

Thanks!


#18

@ ianlee74 - the reason you won’t find a dedicated book on the topic is because it is so elegant in its simplicity that there is not much to write about. MEF started as a codeplex project. Word quickly spread and a couple of versions later it became part of the .NET framework.


#19

If you passed 40 when learning new stuff, I can tell you that MEF is not that simple :-[


#20

I highly recommend to take a look at Prism. I use it at work and I love it.