Global access to current active HttpRequestMessage OR HttpContext
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
My team is building an infrastructure library which will be used by console/other libraries/ASP.NET Core/Azure Functions projects.
We desperately need to extract information from the current active HTTP request for both ASP.NET Core projects and Azure Functions.
Basically, any project using this infra library will register to an exception event which will be raised along with a lot of meta data it collected upon any exception. Exception can occur inside the library or in the referring project. The referring project will handle the raised event and will do whatever it wants with the exception, either log it to DB, write to file or ignore it.
Each exception is added with a lot of information on the current state of the host, process and HTTP information: headers, post/get values, user agent, path etc.
This works great in ASP.NET Core by initialization of "IHttpContextAccessor" during startup. The thing is, I have no idea how to handle this with Azure Functions.
Yes, we're able to pass HttpRequestMessage with my handle error method, i.e.: "Logs.Write(exception, httpRequestMessage)" which is annoying code-wise but OK.
But I can't statically globally access it. Which means, in theory, I have to pass HttpRequestMessage to each and every external method, which are mostly unrelated (Users.AddBalanace() etc).
**I think this is a MUST for Azure Functions.** Not everything in .NET Core is architecturally pixel perfect and this option should be an exception, added to make migrations and newcomers' life so much easier. You really can't expect a developer to add HttpRequestMessage argument to each and every method he writes. So many projects depend on HttpContext.
I.E. if I have a global BL library: "**Users.AddBalance(string userId)**", converting this to "**Users.AddBalance(string userId, HttpRequestMessage httpRequestMessage)**" is NOT the right solution. And right now it is the only solution for that, AFAIK.
Thanks
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.