Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Inject IHttpContextAccessor to CatalogContext's constructor will be destoryed when RevokeAuthenticationEvents.cs handle about CatalogContext's data #938

Open
Cheunglik opened this issue Sep 9, 2023 · 0 comments

Comments

@Cheunglik
Copy link

if I only inject IHttpContextAccessor In CatalogContext's constructor. It' works!
public CatalogContext(DbContextOptions options, IHttpContextAccessor httpContextAccessor) : base(options)
{
var name = httpContextAccessor.HttpContext?.User.Claims.SingleOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value ?? "";
}
I can get the user's ID in the context's consturctor if user logged on.
https://github.com/Cheunglik/eShopOnWeb/commit/5ca53d7675bc98baf0ff9c5e1d27c16e16f922ea
withUserClaims

But I add some's data handling like ICatalogItemViewModelService in RevokeAuthenticationEvents
public RevokeAuthenticationEvents(IMemoryCache cache, ILogger logger, ICatalogItemViewModelService catalogItemViewModelService)
{
_cache = cache;
_logger = logger;
_catalogItemViewModelService = catalogItemViewModelService;
}
https://github.com/Cheunglik/eShopOnWeb/commit/5ca53d7675bc98baf0ff9c5e1d27c16e16f922ea
I can not get the user'ID in the context's consturctor even the user logged on.
withoutUserClaims

I just fork from the original main braches https://github.com/dotnet-architecture/eShopOnWeb and add two simple comments. It 's so easy to reproduce it.
In fact I want to handler some data in cookie's CookieAuthenticationEvents, I will add some tenant's records in user.claims.
When user request controller => service=> repository => dbcontext.
The dbContext can apply modelBuilder.Entity.HasQueryFilter(from userclaim's property) to isolate different tenant's record.

Please assist with the possibilities.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant