Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 788455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:22:03+00:00 2026-05-14T21:22:03+00:00

What are some best practices for using MEF in your code? Are there any

  • 0

What are some best practices for using MEF in your code? Are there any pitfalls to take into account when starting your extensible application? Did you run into anything you should have known earlier?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:22:04+00:00Added an answer on May 14, 2026 at 9:22 pm

    I’m in the midst of building a fully fledged extensible application on MEF (and using WPF with the MVVM pattern). I took the basic application framework that I built and open sourced it as SoapBox Core. I also published a demo based on SoapBox Core over at Code Project: Building an Extensible Application with MEF, WPF, and MVVM.

    I’m not sure if using MVVM applies to you, but if it does, then there’s a lot you might learn by looking at the implementation of MVVM with MEF. Particularly the way it imports Views.

    As far as best practices… I created a nested hierarchy of extensions (so the basic module is called Host, and all it does is compose the application and import a few basic extensions). Then those extensions expose other extension points and the application kind of builds itself when you run it (a cross between composition and extensions).

    To keep everything straight, I put the extension hierarchy into a set of static classes. For instance, here are all the extension points that the core framework provides:

    namespace SoapBox.Core.ExtensionPoints
    {
        public static class Host
        {
            public const string Styles = "ExtensionPoints.Host.Styles";
            public const string Views = "ExtensionPoints.Host.Views";
            public const string StartupCommands = "ExtensionPoints.Host.StartupCommands";
            public const string ShutdownCommands = "ExtensionPoints.Host.ShutdownCommands";
        }
        public static class Workbench
        {
            public const string ToolBars = "ExtensionPoints.Workbench.ToolBars";
            public const string StatusBar = "ExtensionPoints.Workbench.StatusBar";
            public const string Pads = "ExtensionPoints.Workbench.Pads";
            public const string Documents = "ExtensionPoints.Workbench.Documents";
    
            public static class MainMenu
            {
                public const string Self = "ExtensionPoints.Workbench.MainMenu";
                public const string FileMenu = "ExtensionPoints.Workbench.MainMenu.FileMenu";
                public const string EditMenu = "ExtensionPoints.Workbench.MainMenu.EditMenu";
                public const string ViewMenu = "ExtensionPoints.Workbench.MainMenu.ViewMenu";
                public const string ToolsMenu = "ExtensionPoints.Workbench.MainMenu.ToolsMenu";
                public const string WindowMenu = "ExtensionPoints.Workbench.MainMenu.WindowMenu";
                public const string HelpMenu = "ExtensionPoints.Workbench.MainMenu.HelpMenu";
            }
        }
    
        public static class Options
        {
            public static class OptionsDialog
            {
                public const string OptionsItems = "ExtensionPoints.Options.OptionsDialog.OptionsItems";
            }
        }
    }
    

    So if you wanted your extension to add something to the file menu, you would export something that implements IMenuItem with contract name SoapBox.Core.ExtensionPoints.Workbench.MainMenu.FileMenu

    Each extension has an “ID” which is just a string identifier. These existing IDs are defined in another hierarchy:

    namespace SoapBox.Core.Extensions
    {
        public static class Workbench
        {
            public static class MainMenu
            {
                public const string File = "File";
                public const string Edit = "Edit";
                public const string View = "View";
                public const string Tools = "Tools";
                public const string Window = "Window";
                public const string Help = "Help";
    
                public static class FileMenu
                {
                    public const string Exit = "Exit";
                }
    
                public static class ViewMenu
                {
                    public const string ToolBars = "ToolBars";
                }
    
                public static class ToolsMenu
                {
                    public const string Options = "Options";
                }
            }
        }
    }
    

    As you can see FileMenu already contains an Exit extension (that is pre-programmed to close the app). If you wanted to add an extension to the File menu you probably want it to appear before the Exit menu item. IMenuItem inherits from IExtension, which has two properties:

    • InsertRelativeToID
    • BeforeOrAfter

    So your extension would return SoapBox.Core.Extensions.Workbench.MainMenu.FileMenu.Exit for InsertRelativeToID, and would return Before for the BeforeOrAfter property (an enumeration). When the workbench imports all the File menu extensions, it sorts everything based on these IDs. In this way, the later extensions insert themselves relative to the existing extensions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any documentation on Mustache best practices when using on the server (with
I'm trying to adopt some best practices to keep my python code efficient. I've
I'd like to get some community input on best practices for styling your ERB
I'm trying to understand some fundamental best practices using Entity Framework. My EDM design
I was hoping someone could suggest some best practices for configuring Rails applications using
I'm looking to establish some best practices for Android, with regards to code reuse,
I am using ColdFusion 8 and 9. I was reading some ColdFusion best practices
I'm looking for some best practices when using Spring 3 annotations . I'm currently
I was wondering about some best practices for data binding in web forms. For
What are some best practices to keep in mind when developing a script program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.