This project has moved and is read-only. For the latest updates, please go here.

MEF Scope and Provider

Jul 16, 2013 at 12:47 PM
Is there a way to map MEF to use provider instead of directly create the part by itself?
The reason I ask it is because the scope you are allow today are governed by the consumer of the part. What I mean is that the consumer ask for a part using ExportFactory<Part> and it is the one responsible for creating the part and disposing it.

In web application, for example, I have two scopes I want to support: request and session.
I look at Google Guice which remind me of MEF just for the Java world. They also define request and session scope for web application and they achieve it using Providers. They allow to map a requested part to provider, and not directly to implementation, and that way the provider is responsible for creating a new part or return already built part.
The implementation of session scoped provider simply cache the part in the current session dictionary, and the request is cached in the request dictionary.

If I'll be able to use providers with MEF I'll be able to decide on the scope from the declaring side and the consumer side will simply have a "just-works" experience without troubling itself with the scope details.

I hope I made myself clear.

Thank you,