是否可以在 MEF 处理依赖项请求之前拦截 MEF 中的依赖项请求?
这对于实现装饰器和高级生命周期管理非常有用。
就像是...
catalogue.AddInterceptor<IExpensiveService>(b => ... return from pool ...);
甚至...
catalogue.AddInterceptor<IExpensiveService>(b => new Decorator(b()));
(其中“b”是用于解析服务的底层 MEF 解析函数)
不是开箱即用的,但您可以编写自己的出口商 http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.hosting.exportprovider.aspx or 可组合部件目录 http://msdn.microsoft.com/en-us/library/system.componentmodel.composition.primitives.composablepartcatalog.aspx实施来做到这一点。
MefContrib https://github.com/mefcontrib似乎已经实现了类似的东西,看看拦截目录 https://github.com/MefContrib/MefContrib/blob/master/src/MefContrib/Hosting/Interception/InterceptingCatalog.cs。另请参阅此(可能已过时)博客文章 http://pwlodek.blogspot.com/2010/11/introduction-to-interceptingcatalog.html关于它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)