在MEF拦截依赖 [英] Intercepting dependencies in MEF

查看:130
本文介绍了在MEF拦截依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能拦截依赖请求,MEF他们通过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.

喜欢的东西...

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

甚至...

Or even...

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

(其中B是底层MEF分辨率FUNC键解决服务)

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

推荐答案

不开箱即用,但你可以编写自己的<一href="http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.hosting.exportprovider.aspx"相对=nofollow> ExportProvider 或<一href="http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.primitives.composablepartcatalog.aspx"相对=nofollow> ComposablePartCatalog 实施做到这一点。

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

MefContrib 似乎已经实现了这样的事情,看看<一href="https://github.com/MefContrib/MefContrib/blob/master/src/MefContrib/Hosting/Interception/InterceptingCatalog.cs"相对=nofollow> InterceptingCatalog 。也看到这个(可能是过时的)博客帖子一下吧。

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

这篇关于在MEF拦截依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆