The last commit here was at Jul 20, 2012.
Where can we see what is going on with MEF team and what the future plans are?
I put MEF in the core of our application and it is very important to me to see where Microsoft is going with it.
Thank you,
Ido.
Hi Ido,
The team has been focused on other priorities and working on enabling some longer term goals of the framework that are not specific to MEF, which I cannot talk about at this point in time. Please be assured that it is supported by us. We have some ideas on where we want to invest in MEF and we would love to share them out and get feedback as soon as we can get it to a point where we can execute on it.
Thanks for your patience and endorsment.
cheers
-alok
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?William,
I am assuming that you are using the version of MEF that comes with .Net 4.5. Here are a couple of things to get you started.
Let’s assume that you have two classes that implement IPlugin
[Export(typeof(IPlugin))] //Add these attributes to make them discoverable to MEF.
Plugin1: IPlugin In Plugin1.dll
[Export(typeof(IPlugin))]
Plugin2: IPlugin In Plugin2.dll
In your Main in hosting application, you need to define a DirectoryCatalog with the path where the binaries are dropped.
var directoryCatalog=new DirectoryCatalog(“<BINPATH>”)
var container=new CompositionContainer(directoryCatalog)
IEnumerable<IPlugin> plugins= container.GetExportedValues<IPlugin>(); // GetPluginsViaMef2LolKThx[This is the implementation of your method
plugins should have Plugin1 and Plugin2
In case you want your plugins to be completely oblivious to the use of MEF, you can use registration builder to define rules.
var builder=new RegistrationBuilder();
builder.ForTypesDerivedFrom<IDisposable>().ExportInterfaces();
and pass that in to the DirectoryCatalog as follows.
var directoryCatalog=new DirectoryCatalog(“<BINPATH>”,builder)
hope that answers your question. (Excuse the email formatting)
cheers
-alok
William,
for the nuget version of MEF you could use the method in ContainerConfiguration WithAssemblies( ) method.
You would need to pull the assemblies on your own in that case. The attributes should work the same way and the equivalent for registrationbuilder is conventionbuilder
hope that helps
cheers
-alok