MEF: Inheriting from a part? RRS feed

  • Question

  • Hi!

    I'm trying to have a base class imported as part. That is, the base class of a class should be found during composition using a directory catalog.

    What I'm trying to achieve is this:

    I have got multiple versions of a dll exporting the same types. At startup and before composition I select one of these dlls to be used for this run of the program by including it into a directory catalog. Then all derived types (which are parts, too) should derive from the type in the selected dll.

    Is this possible? If yes, how?

    Lots of Greetings!


    Friday, May 10, 2013 2:40 PM


All replies

  • To elaborate:

    The base class dll has the same identity (token etc.) all the time.

    The idea is, for instance, to release a new version, like an alpha version and the program decides to use the new alpha if it's processing test data or the old, stable version for real ("production") data.

    The two versions of the base class dll will be in two directories, one called ALPHA and one called FINAL or something.

    Friday, May 10, 2013 6:35 PM
  • Hi,

    you need an interface that each version must implement. Also you must mark each version to be exported. On composition the version that is found, will be used.

    This may help http://code.msdn.microsoft.com/Creating-a-simple-plugin-b45f1d4e


    Code Samples: Code Samples

    • Proposed as answer by Mike Feng Tuesday, May 14, 2013 4:07 AM
    • Marked as answer by Mike Feng Monday, May 20, 2013 3:54 PM
    Sunday, May 12, 2013 10:19 PM