JamesRandall / FunctionMonkey

Write more elegant Azure Functions with less boilerplate, more consistency, and support for REST APIs. Docs can be found at https://functionmonkey.azurefromthetrenches.com
MIT License
294 stars 50 forks source link

Need a way to access full HttpContext #171

Closed jlocans closed 3 years ago

jlocans commented 4 years ago

First - I think that this is a really great project. Thanks and respect to James. Sadly, learner about the uncertain future of the project.

Nevertheless, I want to ask for a change, hoping that project continues to live on.

So, I don't really understand why HttpContext in IContextProvider has been stripped down, leaving only ClaimsPrincipal, Headers and RequestUrl. Why not expose the whole object? This has caused an issue to which I don't see any workaround. I need to access client's IP address which is found in HttpContext.Connection.RemoteIpAddress. Unfortunately this is not available in Function Monkey. This is just one example, I'm sure there are many more cases where one would need to access whole request context object.

alexeymarkov commented 4 years ago

Add services.AddHttpContextAccessor() and you will be able to access the original HttpContext.

jlocans commented 3 years ago

Thank you @alexeymarkov !

I'll add what is maybe obvious, but you also need to inject IHttpContextAccessor instead of IContextProvider