# Saturday, August 29, 2009

In Preview 6 of Microsoft's Managed Extensibility Framework (MEF), the framework changed the rules on matching multiple exports to a single import.

In previous versions of MEF, the attribute syntax was identical whether we were matching a single item or multiple items to an Import. Both scenarios used the [Import] attribute to tell MEF to find exports with a matching contract.

For example, if your application is using MEF to match a string variable, based on a string contract, you would use code similar to the following

[Import("MyMEFString")]
string SomeString { get; set; }

This works if MEF finds exactly one matching export string, as in the following code.

[Export("MyMEFString")]
string ThatExportedMefString
{
    get
    {
        return "This string was provided by an MEF contract.  It is from  an external assembly.";
    }
}

If there is a chance MEF might find multiple Exports that satisfy the above contract, you would need (in previous versions) to modify the imported type, so that it implements IEnumerable, as in the following example

[Import("MyMEFString")]
IEnumerable<string> SomeStringList { get; set; }

Beginning with MEF Preview 6, the rule for the attribute becomes more strict. If you are matching a number of items into an IEnumerable set of items on your import, you must replace the Import attribute with the ImportMany attribute. In the above example, the Import declaration becomes

[ImportMany("MyMEFString")]
IEnumerable<string> SomeStringList { get; set; }

The main advantage of this change is that ImportMany will not blow up if MEF finds no matching export for the contract. Import throws an exception if it cannot find a matching export.

Of course, your code will need to handle cases in which there are 0 matches, 1 match, or many matches when MEF seeks exports to match this contract. In the above example, that code might look like

foreach (string s in SomeStringList)
{
    Console.WriteLine(s);
}

In my opinion, when you are writing an Import and you don't have control over the Export (for example, if you are allowing third-party vendors to supply the matching Exports), you should always use the ImportMany attribute. The only time you should use the Import attribute is if you are only looking for contract matches in assemblies that you have written and you can guarantee that there will always be exactly one match.

MEF
Saturday, August 29, 2009 8:41:51 PM (GMT Daylight Time, UTC+01:00)
# Friday, August 28, 2009

Episode 45

In this interview, Jessica Moss describes SQL Server Integration Services (SSIS): What it is; how it works; and how to get started learning and using it.

7 mins, 48 secs

Friday, August 28, 2009 9:12:57 AM (GMT Daylight Time, UTC+01:00)
# Wednesday, August 26, 2009

Episode 44

Chris Smith is a software design engineer on the Microsoft Visual F# team. In this interview, Chris describes the uses of F# and how it differs from object-oriented languages, such as C# and Visual Basic.

21 mins, 51 secs

Wednesday, August 26, 2009 4:54:12 AM (GMT Daylight Time, UTC+01:00)
# Monday, August 24, 2009

Episode 43

Kathleen Dollard is the only person I've met who is building a production application using Managed Extensibility Framework (MEF). In this interview, she describes how to use MEF and shares her vision of how it will affect the way we architect applications in the future.

17 mins, 37 secs

Monday, August 24, 2009 4:24:28 AM (GMT Daylight Time, UTC+01:00)
# Sunday, August 23, 2009

Those who attended DevLink last week should enjoy these photos I took. Even if you didn't attend, you may like to see shots of what you missed or people you know.  You can view over 200 photos here.

If you have a very short attention span or if you enjoy the heart-pounding music of Link Wray, the slideshow below is for you.  Turn up your speakers and move your furniture out onto the front lawn before clicking 'Play'.

2 mins, 28 secs

Sunday, August 23, 2009 11:26:29 PM (GMT Daylight Time, UTC+01:00)
# Saturday, August 22, 2009

I started using DasBlog for this blog almost two years ago.

For the past couple months, I've been struggling trying to add a permanent page to my web site. By permanent, I mean a page that is always relevant and is always available at the top of the site; as opposed to a blog post, which is dated and moves down as new blog posts are added.

My biggest problem is that I wanted the new page to have the same theme as all existing pages. It seemed simple enough but DasBlog did not provide an obvious way to do this.

Recently I discovered an old post by Omar Shahine at http://www.shahine.com/omar/FormatPageMacroInDasBlog.aspx

He described in detail exactly what I wanted to do.

Essentially, I create a file named xxx.format.html and add any static HTML I want on my new page. To apply the theme, I need to use FormatPage.aspx, which ships with DasBlog. FormatPage.aspx accepts a parameter path, which points to an HTML document and displays that document with the current theme applied.

After uploading my HTML page, I can apply a theme by linking to FormatPage.aspx?path=DaveSchedule.format.html.

Now I have a link in a tab at the top of every page pointing to my past and upcoming speaking schedule and that page has the same theme as the rest of the site.

Saturday, August 22, 2009 4:43:00 PM (GMT Daylight Time, UTC+01:00)
# Friday, August 21, 2009

Episode 42

The 2009 Lansing Day of .Net was held August 1 at the Jack Breslin Student Events Center in East Lansing, MI. This was the first event that Dennis Burton organized and he discussed it with us here.

8 mins, 28 secs

Friday, August 21, 2009 5:16:31 AM (GMT Daylight Time, UTC+01:00)

I will be presenting "An Introduction To Object Oriented Programming" at the Findlay Area .Net User Group August 25 (next Tuesday) in Findlay, OH. For more information visit the group's web site at http://fanug.org

This is actually my second time speaking at this group but it's the first time since 2002, so they have probably forgotten.

If you are in Northwest Ohio or central west Ohio, please come.

Friday, August 21, 2009 1:52:59 AM (GMT Daylight Time, UTC+01:00)
# Wednesday, August 19, 2009

Episode 41

Sara Ford is the Program Manager for Microsoft's CodePlex site. In this interview, she discusses the CodePlex site, open source software, and what she has in common with an Apollo astronaut.

19 mins, 50 secs
Wednesday, August 19, 2009 6:05:54 AM (GMT Daylight Time, UTC+01:00)
# Tuesday, August 18, 2009

John Kellar stood on stage in the final minutes of the DevLink closing ceremonies, gazing across the audience and smiling. In front of him, someone was introducing the members of the staff that had helped him organize and execute the conference. Behind me, the applause began. A few people in the back stood and clapped; then two more in front stood up; then I stood and applauded; soon, the entire auditorium was on its feet, cheering those who had put together an amazing conference.

John said he wanted to focus on the entire conference experience to make it worthwhile for the attendees. He succeeded at an amazing level.

Here are some highlights from my experience at DevLink 2009

'Configuration Management with Team Foundation Server' presented by Steve Andrews
The first day, all sessions were three hours long. Steve Andrews showed how to configure the automated build settings in TFS. He dug deep into the details of TFS and showed the various options available for continuous integration and how to customize the process.

'Good ways to use Live Mesh' Open Space
I called this session because I wanted to use Live Mesh as my backup strategy, easing my angst about rebuilding a laptop or PC. Jeff Blankenberg showed me the details of this very cool technology, answering all my questions and showing how he used Mesh to backup and share files.  Others looked over our shoulder as he did so, making this a successful Open Space for several people.

'MEF' Open Space
I have been delivering a talk on Managed Extensibility Framework (MEF) for almost year. But in this session, I got to ask questions of Kathleen Dollard, who has been working with this framework on a production application and has some very definite ideas about the future of MEF. It’s startling to me how much I learned during this hour.

'Enhance your .NET Application with SSRS' presented by Jessica Moss
Jessica had some hardware issues in this session, but recovered well enough to put on a solid presentation. I was glad to see because I have a customer looking for a class on SSRS and she looks like a good candidate for that.

'Dot Net Rocks' panel discussion
Prior to the closing ceremonies, Carl Franklin and Richard Campbell recorded an episode of their popular Dot Net Rocks podcast. A panel consisting of Josh Holmes, Jim Holmes, Kathleen Dollard and Billy Hollis discussed whether software development was becoming too complex. It wasn't one of Franklin and Campbell's best shows, but it was fun to watch them perform live.

Networking
Conferences are a chance to meet up with old friends, meet new friends and exchange ideas. DevLink was particularly good for this because so many people attended from outside my geographic region. The usual suspects from Michigan and Ohio were there, but I spoke with people from Atlanta, Virginia, Colorado, Canada and Great Britain.  Hallway conversations were as good as any I’ve had at a conference.  We were even able to meet in a more relaxed atmosphere at several organized evening events. The 3-day format made it possible to establish relationships with people through multiple conversations. John Kellar reminded me that this is not an accident and it's the reason the word "Link" appears in the conference name.

Technology and Friends
I recorded thirteen interviews for my show at this conference. I've already released one episode and cannot wait to produce and share the rest.

This was the best-run community conference I have attended to date. From the time I woke up to the time I went to bed, there was not a minute that I lacked something to do and learn. Often I had to choose between two or three options. I am already looking forward to next year.


DevLink web site

Tuesday, August 18, 2009 1:22:12 PM (GMT Daylight Time, UTC+01:00)