Lawrence Wagerfield
Lawrence Wagerfield

Reputation: 6611

Intercepting dependencies in MEF

Is it possible to intercept dependency requests in MEF before they get handled by MEF?

This would be useful for implementing decorators and advanced lifetime management.

Something like...

catalogue.AddInterceptor<IExpensiveService>(b => ... return from pool ...);

Or even...

catalogue.AddInterceptor<IExpensiveService>(b => new Decorator(b()));

(where 'b' is the underlying MEF resolution func for resolving the service)

Upvotes: 0

Views: 1233

Answers (1)

Wim Coenen
Wim Coenen

Reputation: 66733

Not out of the box, but you can write your own ExportProvider or ComposablePartCatalog implementation to do this.

MefContrib appears to have implemented something like that, take a look at InterceptingCatalog. See also this (possibly outdated) blog post about it.

Upvotes: 1

Related Questions