1
我有什么似乎是直接的MEF导出。MEF和EF Intercepters
[Export(typeof(IDbCommandInterceptor))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class LoggingCommandInterceptor : IDbCommandInterceptor
{
[Import]
private ILogging _ILogger;
public void NonQueryExecuting(
DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
Log(command, interceptionContext);
}
private void Log<TResult>(
DbCommand command, DbCommandInterceptionContext<TResult> interceptionContext)
{
if (!interceptionContext.IsAsync)
{
_ILogger.LogWarn("Non-async command used: {0}", command.CommandText);
}
else
_ILogger.LogTrace("command used: {0}", command.CommandText);
}
ect.....
则线上高达
public class EFConfiguration : DbConfiguration
{
public EFConfiguration()
{
AddInterceptor(new LoggingCommandInterceptor());
}
}
所以,问题是导入[Ilogging在LoggingCommandInterceptor总是空的永远充满,当我检查我的作文containter我看到导出正确注册,所以我为什么我的进口不满意?
如果您手动实例化LoggingCommandInterceptor类,那么MEF永远不会有机会满足任何导入...您应该允许MEF实例化任何需要满足的类。 – BenjaminPaul 2015-03-19 12:10:08
@BenjaminPaul走下那条路我改变我的EFConfiguration到这个[导入] IDbCommandInterceptor _mefInterceptor; public EFConfiguration() { AddInterceptor(_mefInterceptor); }仍然没有运气 – Nrm101 2015-03-19 12:18:21