Skip to content

Instantly share code, notes, and snippets.

@benfoster
Created August 29, 2012 15:40
Show Gist options
  • Save benfoster/3514548 to your computer and use it in GitHub Desktop.
Save benfoster/3514548 to your computer and use it in GitHub Desktop.
Injecting links
public class CustomJsonFormatter : JsonMediaTypeFormatter
{
public override Task WriteToStreamAsync(Type type, object value, System.IO.Stream writeStream,
System.Net.Http.HttpContent content, System.Net.TransportContext transportContext)
{
var objectWithLinks = value as IResourceWithLinks;
if (objectWithLinks != null)
{
objectWithLinks.Links = new[] { new Link { Rel = "Self", Href = "???" } };
}
return base.WriteToStreamAsync(type, value, writeStream, content, transportContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment