MEF Enabled Web (sample)

Oct 1, 2008 at 10:31 PM
Edited Oct 1, 2008 at 10:33 PM
The MEF Enabled Web Application sample is a naive POC that shows a way to integrate MEF capabilities into a Web Application Project. I created it to replace my EventBroker contribution to the CWAB added to the WCSF Contrib project. I myself needed the EventBroking capabilities in a project I was assigned to and so I created this simple yet useful thing. It even featured relaxed delegates.

Naturally MEF completely replaces my small extension.

What do you think of MEF on the Web?

Cheers,

M.
Oct 22, 2008 at 6:57 PM
While reviewing the MEF enabled web app I noticed you are using HttpApplicationState to create and hold the Unity container. I'm wondering if this is a good idea. I might just not understand ASP.NET well enough, so please correct me if I'm wrong.

Wouldn't we wind up with not just the container but every singleton or instance managed by the container in memory on the server until the application is shutdown? If you only have a couple of services whose memory and CPU utilization are well tuned that's probably not a big deal. However, if you build a truly pluggable application with many services won't those that might only be hit a few times in your site hang around in memory until the application shuts down? Is a static field of a custom HttpApplication object any better? Seems like there has to be a caching mechanism to time out the objects not being utilized.

Thanks for your comments.

mousedoc
Oct 22, 2008 at 8:58 PM
Edited Oct 22, 2008 at 9:03 PM
To be perfectly honest the MEF enabled web app is more a proof of concept than anything else! It works for a limited sample only and there is a lot of work left to be done with MEF before it ships. I simply do not know now what the inner workings of MEF will be like.

The general idea was to put global services on a global peg in the app. So you're right; that would mean global services used infrequently would hang around until app shut down.

Unloading a service, I've often found, is easies to leave to the application itself. Some times I use weak reference dictionaries. Sometimes I use that which is known as a life time manager that holds on to the service for some extent of time or other.

Caching policies may also be used to keep a sliding cache of service invocations.

What I wanted to show with the MEF enabled web was quite simply that it run and had some real use in a web scenario. Up until then I'd only seen MEF used with Prism. Being a true webbie I wasn't gonna let that slide! ;~)

I wanted the MEF enabled web to rest on solid ground so I tossed in the Unity container for good measure. It was not really necessary for the sample but it made the picture I tried to paint a bit more complete.

Does this make any sense and does it answer your questions?

Cheers,

Magnus
Oct 22, 2008 at 11:43 PM
Thanks for the quick reply. I think I'll have to retool CompositeWeb so that child containers (module containers that hold module level services) are cached so they can be disposed at a configurable time instead of by garbage collection. The programmer might want to keep them around a little longer than GC but not a true singleton. I've been looking today at MEF, your web app, and a Unity based CompositeWeb port (http://www.codeplex.com/websf/Wiki/View.aspx?title=CWAB%20and%20Unity). I'm getting confused at the moment on ICompositionService, CompositionContainer, and ValueResolver as to where the appropriate place place to hook in Unity or another IoC/DI system. More code/documentation review to do...

Oct 23, 2008 at 1:43 PM
Edited Oct 23, 2008 at 5:50 PM
Your intended approach with the configurable time sounds very interesting, but is this not the same as indicating a specific time to cache?

Please get back to me again if you have any further questions on the matter as I will be looking to evolve the MEF enabled web sample in cooperation whenever someone has something good to suggest for it!

The exact location for the insertion of instances into the container is, I concur, this samples weak point. There must be improovements to be made here!

Cheers,

M.

Techie.notepad
Nov 13, 2008 at 1:46 AM
Edited Nov 13, 2008 at 1:47 AM
Oct 22 at 1:57 PM
While reviewing the MEF enabled web app I noticed you are using HttpApplicationState to create and hold the Unity container. I'm wondering if this is a good idea. I might just not understand ASP.NET well enough, so please correct me if I'm wrong.

Hi mousedoc,

Considering the source, Michael Puleio and Chris Tavaress, my vote would be that its probably the best solution that money can buy - or at least the start of one.   Michael, the Web Client Software Factory (WCSF) guru, wrote this code with Chris shortly after writing a series on how to refactor the WCSF to utilize Unity (an unofficial project); the WCSF does some really cool stuff behind the scenes and Michael knows it like the back of his hand.   Chris Tavaress is the Unity Guru so if you put these two guys together you have some of the best talent Microsoft has to offer. 

Like any tool, the devil is in the details; if misused inefficiency will result but used properly, perhaps implementing "on demand", I trust it will get the job done nicely. 

For details on the MEF.Web project's related files I recommend reading the source:
http://blogs.msdn.com/mpuleio/archive/2008/07/17/proof-of-concept-a-simple-di-solution-for-asp-net-webforms.aspx

Nov 13, 2008 at 4:42 AM
Thanks. Missed this post but saw a later one on Common Service Locator (http://blogs.msdn.com/mpuleio/archive/2008/10/13/finally-a-common-service-locator.aspx). As soon as I finish getting my multiple backups reconciled from 2 simultaneous hard drive crashes and a reinstall of Vista (uggh, not impressed with Vista so far) I was going to try to figure out how to put it into WCSF and/or MVC. I hope to get at least a proof of concept in place over the weekend using Unity as the DI system.
From: [email removed]
Sent: Wednesday, November 12, 2008 6:46 PM
To: [email removed]
Subject: Re: MEF Enabled Web (sample) [MEFContrib:36848]

From: BillKrat

Oct 22 at 1:57 PM
While reviewing the MEF enabled web app I noticed you are using HttpApplicationState to create and hold the Unity container. I'm wondering if this is a good idea. I might just not understand ASP.NET well enough, so please correct me if I'm wrong.

Hi mousedoc,

Considering the source, Michael Puleio and Chris Tavaress, my vote would be that its probably the best solution that money can buy - or at least the start of one. Michael, the Web Client Software Factory (WCSF) guru, wrote this code with Chris shortly after writing a series on how to refactor the WCSF to utilize Unity (an unofficial project); the WCSF does some really cool stuff behind the scenes and Michael knows it like the back of his hand. Chris Tavaress is the Unity Guru so if you put these two guys together you have some of the best talent Microsoft has to offer.

Like any tool, the devil is in the details; if misused inefficiency will result but used properly, perhaps implementing "on demand", I trust it will get the job done nicely.

For details on the MEF.Web project's related files I recommend reading the source:
http://blogs.msdn.com/mpuleio/archive/2008/07/17/proof-of-concept-a-simple-di-solution-for-asp-net-webforms.aspx

Nov 13, 2008 at 4:57 AM
Edited Nov 13, 2008 at 4:58 AM
[mousedoc] Thanks. Missed this post but saw a later one on Common Service Locator (http://blogs.msdn.com/mpuleio/archive/2008/10/13/finally-a-common-service-locator.aspx). As soon as I finish getting my multiple backups reconciled from 2 simultaneous hard drive crashes and a reinstall of Vista (uggh, not impressed with Vista so far) I was going to try to figure out how to put it into WCSF and/or MVC. I hope to get at least a proof of concept in place over the weekend using Unity as the DI system.

Sorry to hear about your Vista issues;  I recently had to redo my development server (Windows Server 2008) when I misconfigured an FTP port and opened a door for hackers; didn't know the extent so I just wiped it and am still in the process of installing (MOSS, VS2008, etc).   As for Vista I've been fortunate - been using it since Beta and don't have to rebuild my development PC near as often as I did with XP (I install lots'a betas).

Thanks for the link - I missed that one.

Are you interested joining the MEFContrib team?  Sounds like what your doing is right up our alley.  We could use more Coordinators and Developers to help us keep things moving.   If interested just let me know to what extent you can contribute (position you would like).   Don't let the fact that you havn't started stop you from signing up - perhaps the existing team (or new team members) can assist you with getting MEF integrated into WCSF and/or MVC.  We could stub your project into the solution for when you have time.

No worries if you don't have the time :)