Created
October 25, 2020 00:01
-
-
Save xximjasonxx/a6bc2ca30663e9e078c44000188fd381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContextAccessor : IContextAccessor | |
{ | |
public IDictionary<string, string> QueryString | |
{ | |
// assume .AsDictionary() is an extension method that takes the QueryString struct and converts it to a Dictionary | |
get { return HttpContext.Current.Request.QueryString.AsDictionary(); } | |
} | |
} | |
public interface IContextAccessor | |
{ | |
IDictionary<string, string> QueryString { get; } | |
} | |
[ApiController] | |
[Route("api/test") | |
public class TestController : ControllerBase | |
{ | |
private readonly IContextAccessor _contextAccessor { get; set; } | |
public TestController(IContextAccessor contextAccessor) | |
{ | |
_contextAccessor = contextAccessor; | |
} | |
public IActionResult Get() | |
{ | |
return Ok(_contextAccessor.QueryString["name"]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment