Quantcast
Channel: Managed Extensibility Framework
Viewing all articles
Browse latest Browse all 265

New Post: Simple start-to-end example for MEF2?

$
0
0
I'm trying to eval MEF2 right now, but I'm having tons of problems figuring it out due to a number of factors (e.g., MEF2 is in flux, searches bring up MEF1 results, I'm dumb, etc).

My goals are exceedingly simple, so I'm hoping that someone who understands how it fits together can point me in the correct direction.

What I've got so far is a very simple console solution with two projects, one that hosts a plugin interface and one that implements it. The implementing project throws its built DLL into the bin folder of the plugin host, so that after building the assembly containing the DLL should be easily discoverable. The plugin host knows nothing about the implementer, other than any implementers are going to be accessible in the bin folder.

My goal is to do the following:
  1. Run the plugin host console application
  2. Spin up MEF2, telling it that I want types that implement IPlugin (original, I know)
  3. Get new instances of all types that implement IPlugin every time I ask MEF2 for it
  4. Have a beer, because MEF is doing all the heavy work for me, and I'm done
What I have done is create my two projects, and in the plugin host, and a bunch of MEF2 code that doesn't do anything.

So, given the following plugin defintion
    public interface IPlugin
    {
        void Run();
    }
and the given console program:
class Program
{
    static void Main(string[] args)
    {
        var plugins = GetPluginsViaMef2LolKThx();
        foreach(var plugin in plugins)
            plugin.Run();
        Console.ReadLine();
    }

    private static IEnumerable<IPlugin> GetPluginsViaMef2LolKThx()
    {
        throw new NotImplementedException("HALP!");
    }
}
could somebody do me a major solid and tell me how I can implement that method?

Viewing all articles
Browse latest Browse all 265

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>