Reputation: 10265
I'm pretty new to MEF, I always used to use autofac, which automatically registers all the "Web Request"-scoped objects in the life time scope of the Request, so you can always resolve HttpRequestBase and similar objects in dependencies.
Is there a way to modify the MEF container registration to be able to resolve this dependency?
[Export(typeof(ICustomerContext))]
public class WebCustomerContext : ICustomerContext
{
private readonly HttpRequestBase request;
[ImportingConstructor]
public WebCustomerContext(HttpRequestBase request)
{
this.request = request;
}
}
Upvotes: 3
Views: 186
Reputation: 547
I think you will get the behavior you want if you export your part using the NonShared
creation policy. That way, a new instance of the part will be created for each request:
[PartCreationPolicy(ComponentModel.Composition.CreationPolicy.NonShared)]
Upvotes: 0