Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MEF Question

MEF Question

Scheduled Pinned Locked Moved C#
helpquestiondocker
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    Currently I'm loading plugins like this

    private void LoadPlugins()
    {
    var pluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
    var directoryCatalog = new DirectoryCatalog(pluginPath);
    var container = new CompositionContainer(directoryCatalog);
    // Problem: This syntax required the interface to be compiled into this app
    var plugins = container.GetExportedValues();
    }

    As the comment says, the interface is required to be compiled into this app. Is there a way to load MEF plugins without the host app knowing about the interface?

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    M D P 3 Replies Last reply
    0
    • K Kevin Marois

      Currently I'm loading plugins like this

      private void LoadPlugins()
      {
      var pluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
      var directoryCatalog = new DirectoryCatalog(pluginPath);
      var container = new CompositionContainer(directoryCatalog);
      // Problem: This syntax required the interface to be compiled into this app
      var plugins = container.GetExportedValues();
      }

      As the comment says, the interface is required to be compiled into this app. Is there a way to load MEF plugins without the host app knowing about the interface?

      If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Caveat - I have not used MEF or plug ins. Uhm that does not seem to make sense, the host application needs to code against the functionality of the plug in, hence the required interface. I am scratching my head trying to figure out a use case for not having an interface for the plug in. I will be interested in other responses :-O

      Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

      1 Reply Last reply
      0
      • K Kevin Marois

        Currently I'm loading plugins like this

        private void LoadPlugins()
        {
        var pluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
        var directoryCatalog = new DirectoryCatalog(pluginPath);
        var container = new CompositionContainer(directoryCatalog);
        // Problem: This syntax required the interface to be compiled into this app
        var plugins = container.GetExportedValues();
        }

        As the comment says, the interface is required to be compiled into this app. Is there a way to load MEF plugins without the host app knowing about the interface?

        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        I don't think you can get rid of the interface. How is the host app supposed to know how to call the methods in the plug-in, and what they do, if the plug-in doesn't implement some kind of interface?

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        1 Reply Last reply
        0
        • K Kevin Marois

          Currently I'm loading plugins like this

          private void LoadPlugins()
          {
          var pluginPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
          var directoryCatalog = new DirectoryCatalog(pluginPath);
          var container = new CompositionContainer(directoryCatalog);
          // Problem: This syntax required the interface to be compiled into this app
          var plugins = container.GetExportedValues();
          }

          As the comment says, the interface is required to be compiled into this app. Is there a way to load MEF plugins without the host app knowing about the interface?

          If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          I can see where you are going with this but you have the problem inverted. It sounds like you have a contract that you have created in a plugin assembly and you are trying to use MEF to load that assembly, which has already been linked with the application. Rather than doing this, you would normally have the interface defined in an assembly that just contains contracts. Both the plugins and the application host will be linked with that assembly but they will not share any code and the application host does not have to know anything about the plugins other than that they share an interface. That way you keep them both from knowing about each other, as they rely on the intermediary.

          This space for rent

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups