Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public interface IQueryContextFactory
  2. {
  3. QueryContext Create(string query, HttpRequest request);
  4. }
  5.  
  6. internal class HttpRequestQueryContextFactory : IQueryContextFactory
  7. {
  8. public QueryContext Create(string query, HttpRequest request)
  9. {
  10. if (string.IsNullOrEmpty(query))
  11. throw new ArgumentNullException(nameof(query));
  12. if (request == null)
  13. throw new ArgumentNullException(nameof(request));
  14.  
  15. return new QueryContext
  16. {
  17. Method = request.Method,
  18. QueryString = string.Concat(query, request.QueryString),
  19. Parameters = request.Query.ToDictionary(x => x.Key, x => x.Value.ToString().Replace(""", string.Empty)),
  20. Headers = request.Headers.ToDictionary(x => x.Key, x => x.Value.ToString())
  21. };
  22. }
  23. }
  24.  
  25. [HttpGet]
  26. public IActionResult Process(string query)
  27. {
  28. (...)
  29. var ctx = _contextFactory.Create(query, Request);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement