.net Mef 与企业库 5.0
我想将 mef 与 Enterprise Library 5.0 的日志记录和异常块一起使用。
我正在做的是定义 MEF 在目录中查找的插件。然后它为我导入它。不过,我也在插件中使用日志记录和异常处理,并且我希望能够通过 mef 插入 LogWriter 和 ExceptionWriter 的实例。该示例向您展示了如何使用 unity 来完成此操作,但由于我使用 mef 来获取插件并实例化它,所以这是行不通的。
谢谢
I am wanting to use mef with the Logging and Exception Blocks of Enterprise Library 5.0.
What I am doing is I have a plugin defined that MEF is looking for in a directory. It then imports it for me. However I am using logging and exception handling in the plugin also and I would like to be able to insert the instance of the LogWriter and ExceptionWriter via mef. The example shows you how to do it with unity which won't work since I am using mef to get the plugin and instantiate it.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用如下类导出
LogWriter
:请注意,MEF 通常只会调用此属性 getter 一次,除非导入程序要求
CreationPolicy.NonShared
。如果您想强制执行单例行为,则可以向类显式添加[PartCreationPolicy(CreationPolicy.Shared)]
属性。You can export
LogWriter
with a class like this:Note that MEF will typically call this property getter only once, except if an importer demands
CreationPolicy.NonShared
. If you want to enforce singleton behavior, then you can explicitly add a[PartCreationPolicy(CreationPolicy.Shared)]
attribute to the class.