Skip to content

Adding ITraceWriter Breaks API Versioning #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
commonsensesoftware opened this issue Apr 28, 2017 · 0 comments · Fixed by #121
Closed

Adding ITraceWriter Breaks API Versioning #119

commonsensesoftware opened this issue Apr 28, 2017 · 0 comments · Fixed by #121

Comments

@commonsensesoftware
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant