views:

225

answers:

3

I have an ASP.net MVC application that is using NHibernate under the covers for data access. I'm using the Windsor container to handle injecting ISession references into each controller.

This works great, but now I'm looking to expand my application with a pluggable architecture so that I can have a core product and specific add-ons. I found a great article on doing this with MEF.

My question is how to make the Windsor container and MEF container, life/work together so that I can achieve this. There was an article (http://codebetter.com/blogs/glenn.block/archive/2009/10/31/should-i-use-mef-with-an-ioc-container.aspx) by Glenn Block that talked about this exact issue. Then end then said that the next article would show you how to do this, but there's no part 2.

Has anyone created an application like this using asp.net mvc, mef, nhibernate, castle windsor?

A: 

There are more than one possible approaches you might use depending on what you'd like to achieve.

Ditch Windsor in favor of MEF, if possible. If you don't use Windsor's more advanced features, you could easily use MEF instead of Windsor. (Read this post to see if it is suitable for you.)

If you'd like to stick to both of them, read this. (Perhaps this is the same post you mentioned?)

As Glenn wrote, it is perfectly reasonable to have both MEF and Windsor. Here's what I think:

  • Windsor serves as an IoC container for the actual components in your app
  • MEF should be responsible for external components and 3rd party extensions in your app

This should also answer the questions that Glenn raised at the end of his blog post. (And btw, the comments are also worth to read, he says he has a working bridge for Castle.)
Some more stuff you can find in this question.

Hope this helps.

Venemo
I wouldn't call them "advanced features", in fact they're stock features for any decent IoC container. MEF doesn't have many of those features because it's *not* intended to be used as an IoC container.
Mauricio Scheffer
@Mauricio - Yes, you are right. MEF is *not meant* to be an IoC container, yet it can be used for basic IoC purposes.
Venemo
+1  A: 

I have spiked small prototype of Windsor->Mef integration 6 months ago here. It is targetting the scenario you seem to be implementing, where you bootstrap your application with Windsor, and want to use MEF for extensibility. You can check it out, perhaps it'll give you some ideas

Krzysztof Koźmic
A: 

The Who Can Help Me application is using ASP.NET MVC, Castle Windsor and MEF and NHibernate. Worth a look for some ideas.

Jafin