依赖注入:SimpleTraceWriter 类型必须派生自 ITraceWriter
Dependency Injection: The type SimpleTraceWriter must derive from ITraceWriter
我正在使用 Ninject 进行 DI。其中一行给了我奇怪的错误:
The type SimpleTraceWriter must derive from ITraceWriter.
Parameter name: service
{"The type SimpleTraceWriter must derive from ITraceWriter.\r\nParameter name: service"}
出错的代码行:
config.Services.Replace(typeof(ITraceWriter), new SimpleTraceWriter(WebContainerManager.Get<ILogManager>()));
但是 SimpleTraceWriter 实现了 ITraceWriter:
SimpleTraceWriter 代码:
public class SimpleTraceWriter : ITraceWriter
{
private readonly ILog _log;
public SimpleTraceWriter(ILogManager logManager)
{
_log = logManager.GetLog(typeof(SimpleTraceWriter));
}
public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
{
var rec = new TraceRecord(request, category, level);
traceAction(rec); WriteTrace(rec);
}
...
ITraceWriter 代码:
public interface ITraceWriter
{
void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction);
}
System.Web.Http.Tracing 命名空间中还有另一个 ITraceWriter 接口。尝试在导致错误的行中指定名称空间:
config.Services.Replace(typeof(MyNamespace.ITraceWriter), new SimpleTraceWriter(WebContainerManager.Get<ILogManager>()));
我正在使用 Ninject 进行 DI。其中一行给了我奇怪的错误:
The type SimpleTraceWriter must derive from ITraceWriter.
Parameter name: service
{"The type SimpleTraceWriter must derive from ITraceWriter.\r\nParameter name: service"}
出错的代码行:
config.Services.Replace(typeof(ITraceWriter), new SimpleTraceWriter(WebContainerManager.Get<ILogManager>()));
但是 SimpleTraceWriter 实现了 ITraceWriter:
SimpleTraceWriter 代码:
public class SimpleTraceWriter : ITraceWriter
{
private readonly ILog _log;
public SimpleTraceWriter(ILogManager logManager)
{
_log = logManager.GetLog(typeof(SimpleTraceWriter));
}
public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
{
var rec = new TraceRecord(request, category, level);
traceAction(rec); WriteTrace(rec);
}
...
ITraceWriter 代码:
public interface ITraceWriter
{
void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction);
}
System.Web.Http.Tracing 命名空间中还有另一个 ITraceWriter 接口。尝试在导致错误的行中指定名称空间:
config.Services.Replace(typeof(MyNamespace.ITraceWriter), new SimpleTraceWriter(WebContainerManager.Get<ILogManager>()));