MEF CTP2 released with source code.

My team released MEF CTP2 on codeplex at http://www.codeplex.com/MEF, this time with source code. We also created a number of documents (i.e. wiki pages) and samples that demonstrate how to use MEF.

What problems does MEF solve?

MEF presents a simple solution for the runtime extensibility problem. Until now, any application that wanted to support a plugin model needed to create its own infrastructure from scratch. Those plugins would often be application-specific and could not be reused across multiple implementations.
  • MEF provides a standard way for the host application to expose itself and consume external extensions. Extensions, by their nature, can be reused amongst different applications. However, an extension could still be implemented in a way that is application-specific. Extensions themselves can depend on one another and MEF will make sure they are wired together in the correct order (another thing you won't have to worry about).
  • MEF offers a set of discovery approaches for your application to locate and load available extensions.
  • MEF allows tagging extensions with additional metadata which facilitates rich querying and filtering

[MEF Overview]

By all means please provide us with what you like and\or dislike about MEF at Discussions.

Published Tuesday, September 09, 2008 10:28 PM by puzzlehacker
Filed under: ,

Comments

# re: MEF CTP2 released with source code.

I looked at the example in the Codeplex. I am wondering what would happen if I create another class that implements IMessageSender in the same Assembly.

for example,

all the code as in the example and then add this

[code]

public class regularMailer : ImessageSender

{

........

public void Send(....) //.... means if there are parameters that will be added

{

  System.Console.WriteLine("generate a PDF version and print");

}

}

[/code]

now I will have two classes that have the same footprint of IMessageSender.

Also, what if I want to create different assemblies and put them in the same folder? How will the MEF example work?

Wednesday, September 10, 2008 10:05 AM by Gunshu

# re: MEF CTP2 released with source code.

At the rate I am confused about MEF I will be flooding with lot of comments in this thread :)

I wrote a small app to do a task scheduler. It is a simple app that runs several tasks in their own thread. The code below is something I whiffed in my lunch time. The point I am trying to emphasis ( at least that is what I think ) is that something similar to MEF / plugin can be done without doing anything application specific(as defined by the author).

Here is my code:

------------------------------------------

static void Main(string[] args)

{

   Console.WriteLine("Starting FluEmails....at {0}", System.DateTime.Now.TimeOfDay);

   ArrayList taskStack = getTasks();

   foreach(object aTask in taskStack)

   {

      ITask thisTask = (ITask)aTask;

      ThreadStart task = new ThreadStart (thisTask.execute );

      Thread thread = new Thread (task);

      thread.Start ();

   }

   Console.WriteLine("Exiting FluEmails  ..... at {0}",System.DateTime.Now.TimeOfDay );

   Console.ReadLine ();

}

static ArrayList getTasks()

{

ArrayList allTasks = new ArrayList();

   Assembly assembly = Assembly.Load(Assembly.GetCallingAssembly().FullName );

   foreach (Type type in assembly.GetTypes())

   {

if (type.IsClass == true)

{

// create an instance of the object

try

{

object ClassObj = Activator.CreateInstance(type);

if (ClassObj is ITask )

{

allTasks.Add((ITask)ClassObj);

}

}

catch(MissingMethodException ex)

{

Console.WriteLine (ex.Message);

}

}        

   }

   return allTasks;

}

---------------------------------------------

ITask is an interface that has execute() method.

some task classes that I created are:

--------------------------------

public class EmailTask :ITask

{

public EmailTask()

{

}

public void execute()

{  

//get Data from database

//send emails

}

}

public class Announcer :ITask

{

public Announcer()

{

}

public void execute()

{

keepShoutingIDID();

}

}

----------------------------------------------

So how does MEF benefits over my approach?

Wednesday, September 10, 2008 4:38 PM by Gunshu

# re: MEF CTP2 released with source code.

Q1: If you want to accept multiple you just import a collection of IMessageSenders.

Q2: That works great for a small set dependencies but it won't scale very well and plus you would need to duplicate that code in every application you want to use it in. MEF is going to be part of framework so anyone can use it to accomplish such tasks in a more general fashion.

For more questions it may be better if you post them at www.codeplex.com/.../List.aspx because everyone on my team will help answer them and they will also better help others in the community.

Wednesday, September 10, 2008 10:54 PM by puzzlehacker

Leave a Comment

(required) 
(required) 
(optional)
(required)