Skip to content

Adding ITraceWriter Breaks API Versioning #119

Closed
@commonsensesoftware

Description

@commonsensesoftware

Symptoms

When ITraceWriter is registered with ASP.NET Web API some API-versioned routes fail to resolve. This appears to only affect convention-based routes, which means it also affects OData services.

Repro

To reproduce the behavior, register any ITraceWriter implementation.

public class MyTraceWriter : ITraceWriter
{
  public void Trace(
      HttpRequestMessage request,
      string category,
      TraceLevel level,
      Action<TraceRecord> traceAction )
    {
         // TODO: tracing operations
    }
}

public static class WebApiConfig
{
  public void Register( HttpConfiguration configuration )
  {
      configuration.Services.Replace( typeof( ITraceWriter ), new MyTraceWriter() );
      // TODO: remaining configuration
  }
}

Analysis

The behavior appears to be caused by the decorators injected into Web API when a ITraceWriter
is registered. The equality comparisons required to match controllers and actions fail when the corresponding types are decorated with tracers.

Proposed Resolution

The HttpControllerDescriptor and HttpActionDescriptor types must be undecorated using the Decorator.GetInner method before performing any equality comparisons.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions