# Sunday, June 27, 2010

Since I’m getting back into blogging, I figured I would make upgrade my version of DasBlog to v2.3, change the theme, and spruce things up! I hope all two of you enjoy the new look :)

Sunday, June 27, 2010 3:55:20 PM (Alaskan Daylight Time, UTC-08:00)
# Saturday, June 26, 2010

This morning I thought I would sit down with my Mac and play with doing .NET development for OS X. I had previously tried, but always found things to be really frustrating. All the Cocoa bindings were out of date, and the WinForms stuff looked terrible, etc. But Miguel wrote a blog post a while back indicating they are getting serious about developing a native solution for OS X.

I downloaded the experimental version of MonoDevelop 2.4 from Michael Hutchinson blog but quickly found out the experimental version of MonoDevelop (based on 2.4 RC 4) was out dated. So I upgraded to MonoDevelop 2.4, opened it, and noticed that MonoMac wasn't an available add-in in the RTM version of MonoDevelop.

So I did what any self respecting geek would do, I started digging around inside the bundle for the experimental version of MonoDevelop from Michael Hutchinson, and found the MonoMac addin hidden inside at the path MonoDevelop.app/Contents/MacOS/lib/monodevelop/Addins/MonoDevelop.MonoMac. I copied the folder to the appropriate place of the RTM version of MonoDevelop 2.4 and everything works as expected!

Download it

Download MonoDevelop, copy it to your Applications folder. then open the contents of MonoDevelop.app, and extract MonoDevelop.MonoMac to Contents/MacOS/lib/monodevelop/Addins/. Restart MonoDevelop, and now you should be able to create a new MonoMac project!

Update

I missed two other files that updated in MonoDevelop.IPhone, download the new MonoDevelop.Addins.zip (490.49 KB) and extract it to the same place.

Saturday, June 26, 2010 3:02:05 PM (Alaskan Daylight Time, UTC-08:00)
# Friday, April 03, 2009

Background

For a project I'm doing, I have a task model for the various pieces. In the beginning, I was manually creating a List<ITask>. As I kept adding tasks to run, I started thinking about hacking some code together to rifle through my assembly and pull back all the classes which implement ITask.

Then I remember hearing about Managed Extensibility Framework (MEF). I did some searching, found the MEF home page, and even read the MEF overview. But none of that told me what I really wanted to know, what's the fastest way to get started using MEF as a component loader?

I did some more searching and found the dnrTV episode "Glenn Block on MEF, the Managed Extensibility Framework" and after 20-30 minutes they finally got down to how to create a plugin for your app.

But what I really wanted, and I bet a lot of others, is a quick start guide for creating a plugin.

Solution

Download the latest version of MEF, as of this writing its Preview 4. Grab the System.ComponentModel.Composition.dll from the bin folder and stash it somewhere. Make a reference to said dll in your project.

On your plugin class, add Export attribute:

[Export(typeof(IPlugin))]
public class Foo : IPlugin { ... }

In your plugin consumer, create a property to hold your plugins, and add the Import attribute:

[Import(typeof(IPlugin))]
internal IList<IPlugin> _myPlugins { get; set; }

Now, tell MEF where to get the plugins at (line 2), and where you want MEF to fulfill any plugins (line 5):

private void LoadPlugins() { var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); var container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddPart(this); container.Compose(batch); }

 

I put my call to the LoadPlugins method in the constructor.

Now, spin through your plugins and do the work:

Console.WriteLine("Found {0} plugins", _myPlugins.Count);
foreach (var plugin in _myPlugins) {
    Console.WriteLine(plugin.Name);
}

 

Download the complete source to this (really, only about 10 extra lines to glue things together) and have fun!

kick it on DotNetKicks.com
.NET | C# | HowTo | MEF
Friday, April 03, 2009 8:37:33 PM (Alaskan Standard Time, UTC-09:00)