dotnet / dotnet/extensions

Cannot Access HttpContextAccessor inside hybridcache factory method

Open
#5,648 13 comments 12 reactions 0 assignees View on GitHub
area-caching-hybrid bug
Dominant language
C#
Stars
3.2k
Forks
894
Avg merge
1d 12h
Merged PRs (30d)
23

Description

### Description

hello, i was trying the hybrid cache and noticed that when I'm inside the factory of the new hybridcache in GetOrCreateAsync and tried to access httpcontext but it was null.

this is when I'm inside the factory and try to access httpcontext to get user Identity or empty Guid and as you can see its empty
![Image](https://github.com/user-attachments/assets/84ae2035-9b1d-426a-a468-53e3d1f0b8f4)

and after I'm out of the cache in the same request I can access it and its filled:
![Image](https://github.com/user-attachments/assets/74ebbcf9-7d3c-4030-bd5c-34b4619e8117)

### Reproduction Steps

injecting IHttpContextAccessor and then try to access it inside factory of GetOrCreateAsync

### Expected behavior

i was expecting it to be filled current user identity

### Actual behavior

and because httpcontextaccessor was null i get empty guid

### Regression?

_No response_

### Known Workarounds

_No response_

### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.