.net Mef与企业库5.0 [英] .net Mef with Enterprise Library 5.0
问题描述
我想将mef与Enterprise Library 5.0的Logging和Exception块一起使用.
I am wanting to use mef with the Logging and Exception Blocks of Enterprise Library 5.0.
我正在做的是我有一个定义为MEF在目录中查找的插件.然后将其导入给我.但是我也在插件中使用日志记录和异常处理,我希望能够通过mef插入LogWriter和ExceptionWriter的实例.该示例向您展示了如何统一处理,因为我正在使用mef来获取插件并将其实例化,因此无法正常工作.
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.
谢谢
推荐答案
您可以使用以下类导出LogWriter
:
You can export LogWriter
with a class like this:
public class LogWriterExporter
{
[Export(typeof(LogWriter))]
public LogWriter LogWriter
{
get
{
return new LogWriter(...);
}
}
}
请注意,MEF通常只会调用一次此属性获取器,除非进口商要求CreationPolicy.NonShared
.如果要强制执行单例行为,则可以向该类显式添加[PartCreationPolicy(CreationPolicy.Shared)]
属性.
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.
这篇关于.net Mef与企业库5.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!