The web story and dependency injection

Feb 11, 2009 at 3:35 PM
We have been prototyping an application where MEF contributes as dependency framework and plugin provider. So far I'm very happy about the feature set and delighted by an intuitive API.

Now to the questions.

Our application lives on the web and there will likely be a large volume of instances that needs to be composed. Is this scenario on your list?

The dependency injection capabilities seem to be what we need. I'm thinking that MEF doesn't come with this label not to step on any toes. Based on your knowledge of other frameworks are there any limitations I should be aware of when considering MEF for handling our dependencies?

Thanks
/Cristian
Feb 11, 2009 at 7:32 PM
Hey!

I know a thing or two about this scenario and I guess I will say some things below that you are familiar with too? Hopefully some things that are useful too!?

The obvious way to get MEF into the composition of your web requests is to add your pages to the container and calling compose in a custom httpmodule!

Also perhaps you should opt for using the new CommonServiceLocator adapter for MEF in your logic to encapsulate the MEF root container a little? http://www.codeplex.com/CommonServiceLocator/Wiki/View.aspx?title=MEF%20Adapter&referringTitle=Home You could have this bad boy run on a child container per reqeust to your server!

I have no idea how an app root container and a per request child container would perform on an APT.NET solution but this is one option that I myself would love to explore. Does anyone out there have something to say about that?

If you make a proof of concept on this I'd love to see it enter MEFContrib: http://www.codeplex.com/MEFContrib

Happy hunting!

Cheers,

M.

On Wed, Feb 11, 2009 at 17:35, libardo <notifications@codeplex.com> wrote:

From: libardo

We have been prototyping an application where MEF contributes as dependency framework and plugin provider. So far I'm very happy about the feature set and delighted by an intuitive API.

Now to the questions.

Our application lives on the web and there will likely be a large volume of instances that needs to be composed. Is this scenario on your list?

The dependency injection capabilities seem to be what we need. I'm thinking that MEF doesn't come with this label not to step on any toes. Based on your knowledge of other frameworks are there any limitations I should be aware of when considering MEF for handling our dependencies?

Thanks
/Cristian

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Magnus Mårtensson
Senior Consultant - Scrum Master - MCSD, MCTS
Dotway AB

Tel: +46 (768) 51 00 36

http://blog.noop.se/
Feb 11, 2009 at 10:23 PM
Hej Magnus, It's interesting that you're describing almost verbatim what we've been experimenting. An application scoped container as root for a per-request one. Having a single container instance actually seem to work in our case but somehow it feels wrong to mix singletons and external controller instances. Do you know whether adding parts to the batch modifies the container's state?

Feb 11, 2009 at 10:29 PM
Hey!

On Thu, Feb 12, 2009 at 00:23, libardo <notifications@codeplex.com> wrote:

From: libardo

Hej Magnus, It's interesting that you're describing almost verbatim what we've been experimenting.

This seems to be the proper approach in a web scenario. We should get this documented as a suggestion for best practice.
An application scoped container as root for a per-request one. Having a single container instance actually seem to work in our case but somehow it feels wrong to mix singletons and external controller instances.

+1
Do you know whether adding parts to the batch modifies the container's state?

If I understand it correctly, though I have not verified, adding parts created by someone else to the container, say by the ASP.NET run time, allows you to control the life cycle of the instances. The container does not per default manage the life cycle of instances you add your self. This is what I think I've understood it as right now. Glenn will be able to confirm this; Glenn?

M.

Dec 5, 2010 at 11:51 AM
Edited Apr 20, 2011 at 12:04 PM

.