Intercepting dependencies in MEF

ぃ、小莉子 提交于 2019-12-02 19:39:33

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/7750640/intercepting-dependencies-in-mef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!