Programming Tip


MEF is the Managed Extensibility Framework, which is a project out on CodePlex. The aim of the project is to allow greater reuse of applications and components. Microsoft has said that they will be using it in the next rev of Visual Studio – so there’s some buy-in there. :)

In dashCommerce we allow you to drop in your own providers for Tax, Shipping, and Payment. There are others coming, but one thing that seems to be tripping people up is how, exactly to pull that off. Now, I think it’s pretty darn easy, but I built it, so it makes perfect sense. ;) In addition, people are doing some pretty amazing things with dashCommerce and the application is growing – quickly. And there is a ton of room for additional functionality and flexibility.

With that in mind I started playing with MEF to see what the basic facilities were. And I had something in mind that I wanted to test right off the bat – dropping assemblies into the bin directory and see if they would auto-magically appear for use by the application. I built a windows service a few years back that allowed you to do just that – it was pretty slick, but I never went any further with it. Well, MEF allows us to make the shift from statically compiled applications to dynamically composed applications. There is a lot of power there. A lot.

So, with my minimal goals in mind, I set out to create a simple Cashier application that would try to charge something (actually, it doesn’t charge anything, but it says it does). On the first pass through, there are no classes that implement IPayment so it looks like this:

 mef-1.gif

If I then browse the solution and drop the Payment assembly into the Cashier\bin\Debug directory and press the space bar, I will see this:

mef-2.gif

You can see that without stopping and restarting the application, it has recognized that I have dropped in an assembly that has a particular type of export in it:

  [Export(typeof(IPayment))]

I can then browse to the Authorize assembly and drop it into the same location and press the space bar once again and I see this:

mef-3.gif

Now it recognizes that it has two classes that implement IPayment and it is exercising the Charge() method on each of them. Now, if we couple this with dropping the configuration controls into a specific location, we will get rid of the registration process that currently has to happen in dashCommerce and we will be on our merry way to composing dashCommerce in a highly flexible way! Very sweet!

[UPDATE:]

I did try to upload the sample solution, but WordPress doesn’t allow the uploading of .zip files. So, I had to do a little thing to get it to work. You can get it here.

DotNetKicks Image

For an small ISV, the trouble you frequently encounter is managing all of the systems, environments, and tools you need to run your business.

One of the fundamental things is source control. I have always been a bit of a source control nut – openly scoffing at people that have asked me to “just develop on the server”. It’s my hangup – I know it. I knew it when they openly scoffed at me in return. :)

But when I started developing software, outside of the corporate environment, I knew this was one of the first things I had to do, and I didn’t feel like wrestling with server upgrades and all the luggage that goes with it. So, I decided to outsource my source control. Some may consider this heresy – hosting my source with a third party, but I figure they have better things to do than sniff around my code trying to figure out if it is any good. :) Well, that, and I have the source for my flux capacitor in my safe deposit box.

I have been using the folks at svnrepository for about two years now I think and I have been really happy with them. Don’t be put off by there minimalist web site – there support has been quite good – the once or twice I have had to ask a question. I wrote a post about this a while back, and this is completely unsolicited – I just like to mention a company I think is doing a nice job and is well worth the money I spend with them.

music note While writing this, I was listening to "The Sun Does Rise" by Jah Wobble’s Invaders of the hearte

DotNetKicks Image

I use the Database Publishing Tool a lot. For some reason the version in Visual Studio didn’t work as well for me, so I have stuck with the free standing version of it. Not sure if there is a version that works with Sql Server 2008 yet, but this one works well for 2000 and 2005.

The problem you may encounter, as I do, is that the resultant script is waaaaaay to large to load into the Sql Server Management Studio. So, once you script out the database, then you can use sqlcmd.exe to run the resultant script on an existing database.

Your command line will look something like this:

C:\>sqlcmd -S YOUR_SQL_SERVER -U USER -P PASSWORD -d DATABASE -i "the_scriptpath"

And here it is in action:

sqlcmd 

music note While writing this, I was listening to "Ancodia" by 808 State

DotNetKicks Image

These have proven to be an excellent help. Check them out here:

http://code.msdn.microsoft.com/PowerCommands

music note While writing this, I was listening to "Beautiful Day" by U2

DotNetKicks Image