Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.