This project has moved and is read-only. For the latest updates, please go here.

Using MEF to override calling Windows Form

Apr 2, 2012 at 8:21 AM


I'm very new to MEF and I just want to know on how to override calling Windows Form.

Before we have a custom defined plugin framework to deal with this but I want to consider using MEF on this but can someone help me to do this?

The concept is that, example I have a form named Form1 with 2 buttons named Button1 and Button2 respectively. 

Now, when we have a client specific request to be done on Form1, what we will do is to create a separate project, inherit the Form1 class and do the UI Changes (probably adding some controls to it) and if some methods were marked as virtual, we override it with the client specific codes.

We have a sort of mapping table that when we call the Form1, instead of calling the base Form1 form, it should call the other customized Form1.

My question would be is that, is this possible with MEF? Or Is there any better approach to this one?

Your help will be highly appreciated.



Apr 2, 2012 at 5:09 PM

Hi - welcome!

At first glance this sounds like the problem space where MEF can be applied. Form1 would be what is called the 'contract' in MEF terminology, while the client-specific forms (including the default one) would be MEF 'parts' that 'export' the Form1 contract.

Designing an extensible app with our without MEF (as your experience would no doubt confirm) can be a fairly tricky design challenge, so naturally you'll need to do some detailed prototyping/investigation before being certain that MEF is the right approach in your situation. Looks promising though!

Best of luck,