JsonContentNegotiator.cs 810 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Http;
  5. using System.Net.Http.Formatting;
  6. using System.Net.Http.Headers;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace Ant.Core.WebApi.Json
  10. {
  11. public class JsonContentNegotiator : IContentNegotiator
  12. {
  13. private readonly JsonMediaTypeFormatter _jsonFormatter;
  14. public JsonContentNegotiator(JsonMediaTypeFormatter formatter)
  15. {
  16. _jsonFormatter = formatter;
  17. }
  18. public ContentNegotiationResult Negotiate(Type type, HttpRequestMessage request, IEnumerable<MediaTypeFormatter> formatters)
  19. {
  20. var result = new ContentNegotiationResult(_jsonFormatter, new MediaTypeHeaderValue("application/json"));
  21. return result;
  22. }
  23. }
  24. }