Best way to share user/request data between layers in asp.net core/ web api. I want to share/propagate the user/request data from Controller to Service, then Service to Repository.
I can use IHttpContextAccessor to use the http context and add items to dictionary to save user information. But, I need to inject it everywhere where I need that information and this is not good practice to use Http refence to Service or Repository layer.
Same challenge with OData, how to pass Odata parameters to from controller to service and then service to repository without passing explicitly.
If the data that you want to pass down the chain is not in the parameter of the controller method but is in the HttpContext properties instead, then I'd create a service that hold that information and populate it from middleware.
This will decouple your lower layers from HttpContext.