拦截MEF中的依赖关系
是否可以在 MEF 处理依赖项请求之前拦截 MEF 中的依赖项请求?
这对于实现装饰器和高级生命周期管理非常有用。
类似...
catalogue.AddInterceptor<IExpensiveService>(b => ... return from pool ...);
甚至...
catalogue.AddInterceptor<IExpensiveService>(b => new Decorator(b()));
(其中“b”是用于解析服务的底层 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是开箱即用的,但您可以编写自己的 ExportProvider 或 ComposablePartCatalog 实现来执行此操作。
MefContrib 似乎已经实现了类似的东西,看看 InterceptingCatalog。另请参阅这篇(可能已过时)关于它的博客文章。
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.